can anyone help me to creat a textBox with the bottom border only in C#? I'm using WinForms and .Net Framework 4.8. Here is the image that I want to create. I need the correct solution for this.
-
What have you tried so far? The idea is to have a Thickness of (0,0,0, borderThickness). – Sotiris Panopoulos Jun 22 '20 at 12:55
-
[This](https://www.syncfusion.com/kb/5507/how-to-customize-the-border-style-and-appearance-in-the-winforms-textboxext) can be helpful for you – Mateech Jun 22 '20 at 12:57
-
1I have tried 3-4 posts answer but none of them work for me. – Jun 22 '20 at 13:07
-
1@Mateech textBox does not contain a definition of BorderSides. – Jun 22 '20 at 13:10
-
1I don't want to use any Third-Party application or application extension. – Jun 22 '20 at 13:12
2 Answers
One way to achieve this would be to dock a label to bottom of TextBox like so
textBox1.BorderStyle = System.Windows.Forms.BorderStyle.None;
var label = new Label()
{
Height = 1,
Dock = DockStyle.Bottom,
BackColor = Color.Black
};
textBox1.Controls.Add(label);

- 239
- 1
- 5
-
1Can you explain what does this line say: `public const int WM_NCLBUTTONDOWN = 0xA1;` – Jun 22 '20 at 13:33
-
@TusharChaurasia It's for knowing if the left mousebutton is being pressed in the non-client area of the control (or form). – LarsTech Jun 22 '20 at 14:01
This specific Textbox that you mentioned by showing a picture is called Material TextBox and such an UI is called Material UI.
You can refer this link:
How to use material design controls c# winforms
The accepted answer will work perfectly fine however if you want something more professional, this could be your choice.
The link explains how to use the Nuget Package MaterialSkin.Updated in your winforms application to make a beautiful UI.
EDIT :
If you are not a coding geek and you need to do it without much coding part, you can create a simple user control with a textbox(design the backcolor and textcolour to suit your needs).
Then add a panel at the bottom with size (0,1) and set it to be visible only when the textbox gets focus.
This link provides examples to add placeholder to textboxes : Placeholder StackOverFlow

- 845
- 1
- 13
- 27
-
1
-
2@TusharChaurasia: Exactly. It is a set of specially designed controls to enhance UI. Pls consult the link provided by me. It is a complete tutorial. – D J Jun 27 '20 at 14:53
-
1
-
1@TusharChaurasia: Oh. No problem. But an easy way is that you can create a user control with a textbox and a panel with size 0,1 and it gives the exact result. Read the **EDIT:** section. Don't forget to upvote if it works! – D J Jul 19 '20 at 04:05
-
@TusharChaurasia: Yes. Adding code is always easier than creating usercontrols. However, it may be a secondary answer! Good luck! – D J Jul 19 '20 at 11:08