System.Windows.Forms.Button을 확장하는 새 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 속성을 변경하여 표시된 문자를 변경할 수 있습니다.