1

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.

Image

2 Answers2

2

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);
teslae
  • 239
  • 1
  • 5
  • 1
    Can 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
0

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

D J
  • 845
  • 1
  • 13
  • 27
  • 1
    Is that third party? –  Jun 27 '20 at 13:25
  • 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
    @D J I do not want to use any Third -part library. –  Jul 19 '20 at 03:53
  • 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