Winforms ToolStripSplitButton 在其下方显示一条灰线,并且仅当鼠标悬停在其上时才会升起
我正在尝试找出 ToolStripSplitButton。 目的是在按下 ToolStripSplitButton 时显示用户控制仪表。 但是,无论我尝试什么设置,按钮下方都会出现一条灰线。
ToolStrip 本身设置为 RenderMode.System,未停靠,并且 ToolStripSplitButton 是其中唯一的组件。
我可以通过引入自定义 ToolStripRenderer 类来删除这条线,但这对于删除控件下这条令人讨厌的深灰色线来说似乎完全是矫枉过正。
我意识到这可能完全是在黑暗中进行的,因为我没有为这些组件提供大量的其余设置,但我希望有人能够深入了解为什么该控件的行为方式如此。
我的第二个问题是关于 ToolStripSplitButton 的行为。 有什么方法可以避免鼠标悬停在组件上之前显示的扁平且无边框的外观吗? 我试图让它与面板中的其余按钮一起具有统一的外观,并且 ToolStripSplitButton 仅在鼠标光标放置在组件上方时才会出现。
这是一个屏幕截图:
非常感谢任何帮助!
I'm trying to figure out the ToolStripSplitButton. The purpose is to display a usercontrol gauge when a ToolStripSplitButton is pressed. However, no matter what settings I try, there is a grey line visible below the button.
The ToolStrip itself is set to RenderMode.System, is not docked, and the ToolStripSplitButton is the only component in it.
I can remove the line by introducing a custom ToolStripRenderer class, but this seems like a total overkill for removing this single annoying dark grey line under the control.
I realize it might be a total shot in the dark since I don't provide the rest of the gazillion settings for these components, but I was hoping someone could provide insight into why this control is behaving the way it does.
My second question is regarding the behaviour of the ToolStripSplitButton. Is there any way to avoid the flat and borderless look that the component displays before the mouse hovers over it? I'm trying to give it a uniform look along with the rest of the buttons in the panel, and the ToolStripSplitButton only appears raised when the mouse cursor is placed above the component.
Here's a screenshot:
Any help is greatly appreaciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于任何感兴趣的人,我最终创建了一个自定义 ToolStripRenderer 类。 在这里,我必须重写几个方法才能获得想要的结果,结果非常好。 为了绘制按钮轮廓,我只使用了 ControlPaint,对于类似下拉选项卡的外观,我使用 ControlDarkDark 系统颜色绘制了一些线条。 不深入细节,已经有几个教程对此进行了描述。 现在,要从 ToolStripDropDownButton 获得类似按钮的行为,必须自己绘制,这似乎很奇怪,但我不排除某个设置可能与另一个设置发生冲突。
如果有人感兴趣的话我可以发布代码。
For anyone interested, I ended up creating a custom ToolStripRenderer class after all. Here I had to override several methods to get the wanted result, and the result came out pretty nice. To draw the button outline I simply used ControlPaint, and for the dropped-down tab-like look I drew some lines with the ControlDarkDark system color. Not to get into the gory details, there are several tutorials out there describing this already. Now, it does seem weird that to get a button-like behaviour from a ToolStripDropDownButton one has to do the drawing oneself, but I'm not ruling out that a setting might have clashed with another somewhere.
I can post the code if anyone is interested.