简体   繁体   中英

Remove left and right side borders

I want my TextBox to look like this
在此处输入图片说明

How can I remove the left and right sides of my TextBox control?

Normally, you'd have to override the OnPaint event to do this, for a Textbox however, this will not work because OnPaint wont get called.

An approach would be to subclass TextBox as described here

However I wouldnt suggest you to do this at all, it sounds like a daunting task to me (never did this myself), espacially when you are new to programming.

Maybe it would suffice to just draw a line above or beneath the TextBox?

-edit-

Maybe this will explain it better:

The TextBox is special in that you can't custom paint it. If you just want a custom border, you can create a new UserControl and add a TextBox with border style set to None. Make sure you leave enough room around the outside of the TextBox for a border. Then paint the border on the UserControl surface. An alternative method would be to handle the WM_NCPAINT message of the TextBox and paint the border then, but that is significantly more complicated.

Source: shawn.ohern in msdn forums: here (Sorry I didnt know how to link to his post directly)

-edit2- This link shows a way to create your own TextBox, which, again, I would not recommend to someone who is new to c# and programming ;)

Windows Forms is based on Win32 API which, unlike WPF which uses declarative language for describing UI, gives you full control of painting your own control.

Take a look here: Custom Control Painting and Rendering .

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