?控件Group Box默認(rèn)的邊框的顏色是白色的,在很多時(shí)候顯得不那么突出。但默認(rèn)的屬性列表里面并沒有提供相應(yīng)的接口。所以只能借助重繪事件。
??????? 網(wǎng)上很多都說(shuō)使用 OnPaint 事件,但是我在事件列表中沒找到,應(yīng)該是隱藏得太深了(需要用 override 關(guān)鍵字來(lái)重寫)。我這里直接使用了 Paint 事件,也可以達(dá)到其效果。
?感謝:http://blog.csdn.net/haoduo123456789001/article/details/51083223
public partial class TestForm : Form
{
public TestForm()
{
InitializeComponent();
this.groupBox1.Paint += groupBox_Paint;
this.groupBox2.Paint += groupBox_Paint;
}
void groupBox_Paint(object sender, PaintEventArgs e)
{
GroupBox gBox = (GroupBox)sender;
e.Graphics.Clear(gBox.BackColor);
e.Graphics.DrawString(gBox.Text, gBox.Font, Brushes.Red, 10, 1);
var vSize = e.Graphics.MeasureString(gBox.Text, gBox.Font);
e.Graphics.DrawLine(Pens.Red, 1, vSize.Height / 2, 8, vSize.Height / 2);
e.Graphics.DrawLine(Pens.Red, vSize.Width + 8, vSize.Height / 2, gBox.Width - 2, vSize.Height / 2);
e.Graphics.DrawLine(Pens.Red, 1, vSize.Height / 2, 1, gBox.Height - 2);
e.Graphics.DrawLine(Pens.Red, 1, gBox.Height - 2, gBox.Width - 2, gBox.Height - 2);
e.Graphics.DrawLine(Pens.Red, gBox.Width - 2, vSize.Height / 2, gBox.Width - 2, gBox.Height - 2);
}
private void TestForm_Load(object sender, EventArgs e)
{
}
}
?
本文摘自 :https://www.cnblogs.com/