我有一个问题,ToolStripStatusLabel
当BorderSides
设置为All
并且我设置了与拥有的背景颜色不同的StatusStrip
背景颜色时:ToolStripStatusLabels 背景颜色在边界外流血 - 这看起来很丑陋。我试图将BorderStyle
属性设置为 Flat 以外的其他设置,但没有成功。
在下面添加的屏幕截图中,您会看到问题 - 蓝绿色的示例是BorderStyle = Adjust
在矩形外绘制边框。但不幸的是,边界完全消失了。
我想要得到的是完全没有流血,就像这个手绘的例子一样。
这可以通过设置或继承或覆盖的特定方法来完成ToolStripStatusLabel
吗?我对编程解决方案持开放态度,但我不知道从哪里开始,所以欢迎任何提示。
通过结合以下 x4rf41和TaW的答案实施的解决方案
由于我使用了多个答案,这使我走上了正确的道路,因此我为问题添加了最终解决方案。
我扩展了ToolStripStatusLabel
类并覆盖了OnPaint
方法。这使我有可能利用类属性并绘制它,因为它会正常绘制自身但不会流血。
public partial class ToolStripStatusLabelWithoutColorBleeding : ToolStripStatusLabel
{
/// <summary>
/// Bugfix to prevent bleeding of background colors outside the borders.
/// </summary>
/// <param name="e"></param>
protected override void OnPaint(PaintEventArgs e)
{
Rectangle borderRectangle = new Rectangle(0, 0, Width - 1, Height - 1);
// Background
e.Graphics.FillRectangle(new SolidBrush(BackColor), borderRectangle);
// Border (if required)
if (BorderSides != ToolStripStatusLabelBorderSides.None)
ControlPaint.DrawBorder3D(e.Graphics, borderRectangle, BorderStyle, (Border3DSide)BorderSides);
// Draw Text if you need it
e.Graphics.DrawString(Text, Font, new SolidBrush(ForeColor), 0,0);
}
}