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?
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.