MBulli
MBulli

Reputation: 1709

Custom look of Textbox

I need to write a complete diffrent looking textbox than the original winforms textbox. In fact I need a different background, how can I achieve this? I tried owner drawing with SetStyle(ControlStyles.UserPaint, true); but this caused a lot of flickers and the text was completly wrong drawn, wrong font, size etc.

Wrtiting a textbox from scratch would be overkill, I think.

Upvotes: 2

Views: 2310

Answers (2)

Hans Passant
Hans Passant

Reputation: 941217

This is not possible. The TextBox class is a wrapper around a native Windows control that has been around since Windows version 2. It had to run on some seriously sucky hardware, they had to break a few rules to make this work. One of which is that it draws parts of itself without using the standard Windows paint cycle. Invalidate() and OnPaint() in Winforms terms. Fixing this behavior wasn't possible due to app-compat problems. Way too much code out there that hacked the control in creative but unpredictable ways.

Accordingly, it isn't possible to intercept the drawing to prevent it from erasing parts of your background image. There is no workaround for this, creating your own is a lot of work. Consider WPF.

Upvotes: 3

John Arlen
John Arlen

Reputation: 6689

If you specifically need a different background on a text box, one work-around is offered here.

Upvotes: 0

Related Questions