C#窗体设计:[21]更改提示框字体
1、新建一个C#应用程序,应用程序命名为Change。
![C#窗体设计:[21]更改提示框字体](https://exp-picture.cdn.bcebos.com/50189b40102a04e20ae624f62b7aa010bd33c29b.jpg)
2、窗体界面设计如下:
![C#窗体设计:[21]更改提示框字体](https://exp-picture.cdn.bcebos.com/ed792abb19efa25f3150dccf59828689a0463b98.jpg)
3、为ToolTip控件添加Draw事件,添加函数toolTip1_Draw(),函数toolTip1_Draw()中添加一下代码:
private void toolTip1_Draw(object sender, DrawToolTipEventArgs e)
{
e.Graphics.FillRectangle(SystemBrushes.ActiveCaption, e.Bounds);
e.DrawBorder();
using (StringFormat sf = new StringFormat())
{
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Center;
using (Font f = new Font("宋体", 8))
{
e.Graphics.DrawString(e.ToolTipText, f, SystemBrushes.ActiveCaptionText, e.Bounds, sf);
}
}
}
![C#窗体设计:[21]更改提示框字体](https://exp-picture.cdn.bcebos.com/efb861bd4c7c34b37b052d0e5841037de0373198.jpg)
4、为窗体添加Load事件,添加函数Form1_Load(),函数Form1_Load()中添加一下代码:
private void Form1_Load(object sender, EventArgs e)
{
toolTip1.ShowAlways = true;
toolTip1.SetToolTip(this.button1, "你选择了提示按钮");
}
![C#窗体设计:[21]更改提示框字体](https://exp-picture.cdn.bcebos.com/e076d77622bc7dc5802335eb5e460596b9142998.jpg)
5、程序运行如下:
![C#窗体设计:[21]更改提示框字体](https://exp-picture.cdn.bcebos.com/d4071b96b814f4d0e047d666cdfe474ec3832398.jpg)