这个控件是什么?是否有分组框!

发布于 2024-10-15 14:37:30 字数 202 浏览 3 评论 0原文

只是对下面显示的控件感到好奇,旁边带有标签的直线。我试图为它找到一个类似的控件,但没有任何组框设置,所以我只是制作了一个高度为 2 的 GroupBox 来复制它。

但是否有实际的控制或设置可以做到这一点?实际控制叫什么?

Internet 选项属性对话框

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?

Internet Options property dialog

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

青春如此纠结 2024-10-22 14:37:30

Spy++ 告诉我们这些实际上是两个独立的 STATIC 控件(类似于中的 Label WinForms)。

  • 第一个只是一个显示“主页”的常规静态文本控件。

  • 第二个具有 SS_ETCHEDHORZ 样式 设置,使其绘制为 3D 线。不幸的是,设置这种样式的能力并没有从 WinForms 中向我们公开。

正如您在问题中指出的那样,有一些技巧/解决方法可以让我们实现类似的外观,例如垂直压缩 GroupBox 控件,或覆盖 OnPaint 方法Label 控件并使用 ControlPaint 类绘制 3D 边框。它们有用,但我从来不喜欢它们。

但您实际上可以自己设置 SS_ETCHEDHORZ 样式,以便可以准确地复制本机 UI。这是一个小类,它正是这样做的。将其添加到您的项目中,进行编译,您应该会看到一个名为“Horizo​​ntalRule”的新控件出现在您的工具箱中。就像使用任何其他控件一样使用它!

public class HorizontalRule : Control
{
    private const int FixedHeight   = 2;

    private const int WS_CHILD      = 0x40000000;
    private const int WS_VISIBLE    = 0x10000000;
    private const int SS_ETCHEDHORZ = 0x00000010;
    private const int SS_ETCHEDVERT = 0x00000011;

    protected override CreateParams CreateParams
    {
        get
        {
            CreateParams cp = base.CreateParams;
            cp.ClassName = "STATIC";
            cp.Style = WS_CHILD | SS_ETCHEDHORZ;
            if (this.Visible)
            {
                cp.Style |= WS_VISIBLE;
            }
            return cp;
        }
    }

    protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified)
    {
        height = FixedHeight;
        base.SetBoundsCore(x, y, width, height, specified);
    }
}

您还可以在 CodeProject 上找到更多详细信息和其他示例代码。

Spy++ tells us those are actually two separate STATIC controls (similar to a Label 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 the OnPaint method of a Label control and using the ControlPaint 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!

public class HorizontalRule : Control
{
    private const int FixedHeight   = 2;

    private const int WS_CHILD      = 0x40000000;
    private const int WS_VISIBLE    = 0x10000000;
    private const int SS_ETCHEDHORZ = 0x00000010;
    private const int SS_ETCHEDVERT = 0x00000011;

    protected override CreateParams CreateParams
    {
        get
        {
            CreateParams cp = base.CreateParams;
            cp.ClassName = "STATIC";
            cp.Style = WS_CHILD | SS_ETCHEDHORZ;
            if (this.Visible)
            {
                cp.Style |= WS_VISIBLE;
            }
            return cp;
        }
    }

    protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified)
    {
        height = FixedHeight;
        base.SetBoundsCore(x, y, width, height, specified);
    }
}

You can also find more detailed information and additional sample code here on CodeProject.

白首有我共你 2024-10-22 14:37:30

几年前我遇到了同样的问题,最终只是为此目的画了一条线。

事实上,我什至使用了一张宽度足够长的固定线图像,以便通过显示图像的所需部分(宽度)来在所有情况下使用它。

从那时起,这个解决方案对我来说效果很好。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文