It's a bug in the "system" renderer, details in this bug report.
Microsoft's response gives a very easy workaround:
1) Create a subclass of ToolStripSystemRenderer, overriding OnRenderToolStripBorder and making it a no-op:
public class MySR : ToolStripSystemRenderer
{
public MySR() { }
protected override void OnRenderToolStripBorder(ToolStripRenderEventArgs e)
{
//base.OnRenderToolStripBorder(e);
}
}
2) Use that renderer for your toolstrip. The renderer must be assigned after any assignment to the toolstrip's RenderMode property or it will be overwritten with a reference to a System.Windows.Forms renderer.
此外,如果您希望应用程序范围内的所有 ToolStrip 实例都使用 MySR,设置 System.Windows.Forms.ToolStripManager.Renderer = new MySR(); 可能会很有用。代码> 默认情况下。
You might want to add type check to avoid missing border on ToolStripDropDownMenu/etc. (since inherited from ToolStrip, it starts same custom renderer usage automatically):
Missed ToolStripDropDownMenu border is not so noticable while using ToolStripSystemRenderer but become real eyesore with ToolStripProfessionalRenderer.
Also, setting System.Windows.Forms.ToolStripManager.Renderer = new MySR(); could be usefull if you want all ToolStrip instances appwide to use MySR by default.
public class ToolStripRender : ToolStripProfessionalRenderer
{
public ToolStripRender() : base() { }
protected override void OnRenderToolStripBorder(ToolStripRenderEventArgs e)
{
if (!(e.ToolStrip is ToolStrip))
base.OnRenderToolStripBorder(e);
}
}
This class is more complete than other!
public class ToolStripRender : ToolStripProfessionalRenderer
{
public ToolStripRender() : base() { }
protected override void OnRenderToolStripBorder(ToolStripRenderEventArgs e)
{
if (!(e.ToolStrip is ToolStrip))
base.OnRenderToolStripBorder(e);
}
}
发布评论
评论(4)
建议的仅隐藏工具条边框而不隐藏下拉菜单边框的解决方案不起作用。
这就是诀窍:
The proposed solution to hide only toolstrip border and not dropdownmenu border does not work.
This is what does the trick:
这是“系统”渲染器中的错误,此错误报告。
Microsoft 的回应提供了一个非常简单的解决方法:
1) 创建
ToolStripSystemRenderer
的子类,覆盖OnRenderToolStripBorder
并使其成为无操作:2) 为您的工具条使用该渲染器。必须在对工具条的 RenderMode 属性进行任何分配之后分配呈现器,否则它将被对 System.Windows.Forms 呈现器的引用覆盖。
It's a bug in the "system" renderer, details in this bug report.
Microsoft's response gives a very easy workaround:
1) Create a subclass of
ToolStripSystemRenderer
, overridingOnRenderToolStripBorder
and making it a no-op:2) Use that renderer for your toolstrip. The renderer must be assigned after any assignment to the toolstrip's RenderMode property or it will be overwritten with a reference to a System.Windows.Forms renderer.
您可能需要添加类型检查以避免
ToolStripDropDownMenu
/etc 上缺少边框。 (由于继承自ToolStrip
,它会自动启动相同的自定义渲染器使用):使用
ToolStripSystemRenderer
时,错过ToolStripDropDownMenu
边框并不那么明显,但会变得非常碍眼使用ToolStripProfessionalRenderer
。此外,如果您希望应用程序范围内的所有
ToolStrip
实例都使用MySR
,设置System.Windows.Forms.ToolStripManager.Renderer = new MySR();
可能会很有用。代码> 默认情况下。You might want to add type check to avoid missing border on
ToolStripDropDownMenu
/etc. (since inherited fromToolStrip
, it starts same custom renderer usage automatically):Missed
ToolStripDropDownMenu
border is not so noticable while usingToolStripSystemRenderer
but become real eyesore withToolStripProfessionalRenderer
.Also, setting
System.Windows.Forms.ToolStripManager.Renderer = new MySR();
could be usefull if you want allToolStrip
instances appwide to useMySR
by default.这个课程比其他课程更完整!
This class is more complete than other!