I was tired of always looking for a way to underline labels like in Windows property dialogs. I created this little control that allows you to set a two-tone line above, below behind or in front of a label (even through it!) to solve that problem.
The image to the left shows the control with the label text "Connection Preferences" using it's default settings.
To use the control in your project, create a new class file, erase everything in the class file, and paste the code snippet here into that new code file. You can change the namespace if you like and you can omit the copyright comment at the top (it's okay, it's open source to the extreme, I don't care if you take credit for it, it wasn't all that complicated to do).
Some of the features:
Offseting the "Line" by setting the left and right offset properties will shorten the line by x number of pixels starting on either the left or right or both.
Offsetting each line tone by setting Line1 or Line2 offset will move the first or second line up into the label text or above the label text.
Each line can have its own thickness setting as well and it's own color setting.
By default the lines are setup to simulate the 3D horizontal line that you might see online or in an application.
Other possible uses could be a label with no text that you auto-size to just draw a line (horizontal only of course) on the designer surface.
Because the control inherits from the label control, all label properties and events are available, no other events were added, but you could if you have some creative ideas.
Some use tips:
- The control by default is set to autosize, if you want the label to stretch past the end of the text (like in the example), switch the autosize property to false and just set the control size to whatever you want and the lines will grow to fit. You might also want to set anchors on the left and right if your form resizes and you want the line to resize when the form does.
- If you want the line to be on the right of the text or the left, you might need to play with the padding, or even better, set the left offset programatically (if you intend to have the text change), otherwise just setting the offsets will achieve this effect.
Feedback/Suggestions are welcome!
If someone would prefer to use a compiled dll file, let me know and I can upload one, but otherwise enjoy!
The control with the line to the right of the label text, achieved by setting LeftOffset = 95, Line1Offset =7, Line2Offset = 6.
The control with the line to the left of the label text, achieved by setting the text alignment to top right, RightOffset = 100, Line1Offset = 7, Line2Offset = 6.
Remember though, the offsets will be different depending on your text length and the height and length of your label, that's why it might be a good idea to set them programmatically.