简体   繁体   中英

Custom textBox in C#

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.

图片

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);

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM