这个控件是什么?是否有分组框!
只是对下面显示的控件感到好奇,旁边带有标签的直线。我试图为它找到一个类似的控件,但没有任何组框设置,所以我只是制作了一个高度为 2 的 GroupBox 来复制它。
但是否有实际的控制或设置可以做到这一点?实际控制叫什么?
Just curious about the control shown below, the straight line with label beside it. I tried to find a similar control for it but there was none nor any group box setting, so instead I just made a GroupBox with a height of 2 that replicates it.
But is there an actual control or setting to do this? And what is the actual control called?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Spy++ 告诉我们这些实际上是两个独立的
STATIC
控件(类似于中的Label
WinForms)。第一个只是一个显示“主页”的常规静态文本控件。
第二个具有
SS_ETCHEDHORZ
样式 设置,使其绘制为 3D 线。不幸的是,设置这种样式的能力并没有从 WinForms 中向我们公开。正如您在问题中指出的那样,有一些技巧/解决方法可以让我们实现类似的外观,例如垂直压缩
GroupBox
控件,或覆盖OnPaint
方法Label
控件并使用ControlPaint
类绘制 3D 边框。它们有用,但我从来不喜欢它们。但您实际上可以自己设置 SS_ETCHEDHORZ 样式,以便可以准确地复制本机 UI。这是一个小类,它正是这样做的。将其添加到您的项目中,进行编译,您应该会看到一个名为“HorizontalRule”的新控件出现在您的工具箱中。就像使用任何其他控件一样使用它!
您还可以在 CodeProject 上找到更多详细信息和其他示例代码。
Spy++ tells us those are actually two separate
STATIC
controls (similar to aLabel
in WinForms).The first is simply a regular static text control that says "Home page".
The second has the
SS_ETCHEDHORZ
style set, which makes it draw as a 3D line. Unfortunately, the ability to set this style is not exposed to us from within WinForms.As you noted in the question, there are some hacks/workarounds that allow us to achieve a similar look, like vertically compressing a
GroupBox
control, or overriding theOnPaint
method of aLabel
control and using theControlPaint
class to draw a 3D border. They work, but I've never liked them.But you can actually set the
SS_ETCHEDHORZ
style yourself so that you can replicate the native UI exactly. Here's a little class that does exactly that. Add it to your project, compile, and you should see a new control appear in your toolbox called "HorizontalRule". Use it just like you would any other control!You can also find more detailed information and additional sample code here on CodeProject.
几年前我遇到了同样的问题,最终只是为此目的画了一条线。
事实上,我什至使用了一张宽度足够长的固定线图像,以便通过显示图像的所需部分(宽度)来在所有情况下使用它。
从那时起,这个解决方案对我来说效果很好。
I had the same problem a couple of years ago and ended up just drawing a line for the purpose.
In fact I even used one fixed line image of a sufficiently long width so that it could be used in all cases by showing the required part (width) of the image.
This solution has worked fine for me ever since.