2
我有一组框,我不喜欢在Visual Studio中可是没有边框颜色属性提供的groupbx所以我用这个代码来创建自己的组框。UI毛刺在我的计划写在自己的组框
public class MyGroupBox : GroupBox
{
private Color _borderColor = Color.Black;
public Color BorderColor
{
get { return this._borderColor; }
set { this._borderColor = value; }
}
protected override void OnPaint(PaintEventArgs e)
{
//get the text size in groupbox
Size tSize = TextRenderer.MeasureText(this.Text, this.Font);
Rectangle borderRect = e.ClipRectangle;
borderRect.Y = (borderRect.Y + (tSize.Height/2));
borderRect.Height = (borderRect.Height - (tSize.Height/2));
ControlPaint.DrawBorder(e.Graphics, borderRect, this._borderColor, ButtonBorderStyle.Solid);
Rectangle textRect = e.ClipRectangle;
textRect.X = (textRect.X + 6);
textRect.Width = tSize.Width;
textRect.Height = tSize.Height;
e.Graphics.FillRectangle(new SolidBrush(this.BackColor), textRect);
e.Graphics.DrawString(this.Text, this.Font, new SolidBrush(this.ForeColor), textRect);
}
}
其作品“精”,我给自己买了一个黑色边框组框,而不是灰色的,当移动窗口中的组框毛刺出来,像这样除了,
是有这个修复或者我将不得不使用Visual Studio组框来防止此问题?我正在使用C#winforms
我刚刚使用了你的groupbox,它没有这样做,你如何初始化你的(不需要控制内部),所以我可以重现它 – EpicKip
不要使用'e.ClipRectangle'。改为使用'this.ClientRectangle'。 –
@EpicKip它刚刚从工具箱中抓起来 – WhatsThePoint