Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Button 如何在windows窗体中为按钮的文本添加上标?_Button_Windows Forms Designer - Fatal编程技术网

Button 如何在windows窗体中为按钮的文本添加上标?

Button 如何在windows窗体中为按钮的文本添加上标?,button,windows-forms-designer,Button,Windows Forms Designer,我正在尝试创建一个类似于Windows10的虚拟键盘。我用按钮来表示键盘上的所有字符。但是我如何在有多个字符的键上放置文本,例如?键,我们还有一个/,那么我该怎么做呢 基本上这就是我想要做的(从Windows10虚拟键盘) 但我现在只能这样做: 那么,我怎样才能添加上标之类的东西,使我的按钮看起来更专业呢 谢谢您可以创建一个扩展System.Windows.Forms.Button的新按钮类 public class SuperscriptButton : Button { [Bro

我正在尝试创建一个类似于Windows10的虚拟键盘。我用按钮来表示键盘上的所有字符。但是我如何在有多个字符的键上放置文本,例如
键,我们还有一个
/
,那么我该怎么做呢

基本上这就是我想要做的(从Windows10虚拟键盘)

但我现在只能这样做:

那么,我怎样才能添加上标之类的东西,使我的按钮看起来更专业呢


谢谢

您可以创建一个扩展System.Windows.Forms.Button的新按钮类

public class SuperscriptButton : Button
{
    [Browsable(true)]
    public event EventHandler SuperscriptChanged;

    [Browsable(true)]
    public string Superscript
    {
        get
        {
            return _superScript;
        }
        set
        {
            _superScript = value;
            OnSuperscriptChanged(EventArgs.Empty);
        }
    }

    private string _superScript;

    public SuperscriptButton()
    {
        TextAlign = System.Drawing.ContentAlignment.BottomRight;
    }

    protected override void OnPaint(PaintEventArgs pevent)
    {
       base.OnPaint(pevent);
       System.Drawing.Graphics g = pevent.Graphics;

       g.DrawString(Superscript, Font, new System.Drawing.SolidBrush(ForeColor), 5, 5);
    }

    private void OnSuperscriptChanged(EventArgs e)
    {
        if(SuperscriptChanged != null)
            SuperscriptChanged(this, e);
        Refresh();
    }
}

现在,您可以在设计器中使用此按钮并更改Superscript属性以更改显示的字符。

您可以创建一个扩展System.Windows.Forms.button的新按钮类

public class SuperscriptButton : Button
{
    [Browsable(true)]
    public event EventHandler SuperscriptChanged;

    [Browsable(true)]
    public string Superscript
    {
        get
        {
            return _superScript;
        }
        set
        {
            _superScript = value;
            OnSuperscriptChanged(EventArgs.Empty);
        }
    }

    private string _superScript;

    public SuperscriptButton()
    {
        TextAlign = System.Drawing.ContentAlignment.BottomRight;
    }

    protected override void OnPaint(PaintEventArgs pevent)
    {
       base.OnPaint(pevent);
       System.Drawing.Graphics g = pevent.Graphics;

       g.DrawString(Superscript, Font, new System.Drawing.SolidBrush(ForeColor), 5, 5);
    }

    private void OnSuperscriptChanged(EventArgs e)
    {
        if(SuperscriptChanged != null)
            SuperscriptChanged(this, e);
        Refresh();
    }
}
现在,您可以在设计器中使用此按钮并更改上标属性以更改显示的字符