Learner
Learner

Reputation: 1376

Remove left and right side borders

I want my TextBox to look like this
enter image description here

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

Upvotes: 2

Views: 2630

Answers (2)

buddybubble
buddybubble

Reputation: 1319

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

Upvotes: 1

Toni Petrina
Toni Petrina

Reputation: 7122

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.

Upvotes: 0

Related Questions