StrataFrame Forum
Home
»
.NET Forums
»
General .NET Discussion
How to "ownerdraw" a textbox
http://forum.strataframe.net/Topic14203.aspx
By Greg McGuffey
-
2/8/2008
I'd like to have a TextBox with a button beside it (it will "zoom" in on the contents by opening another form). However, as you know, there is no OwnerDraw for text boxes (at least I couldn't find it). I attempted a UserControl, that that was waaaaay too much work and a bit wanky to boot because I need a TextBox in all its glory, plus a something clickable right beside it.
To recap: I want a SF TextBox with some clickable element beside it (maybe a label with an image or a button). I'd like this to be a single control that I drop on the form, rather than two (I use this a lot).
So, any ideas on how I might do this?
Thanks!
By Trent L. Taylor
-
2/8/2008
Inherit a textbox, the in the constructor call the SetStyle method:
SetStyle(UserPaint, True)
When you do this, you can then override the OnPaint method and get to rendering:
Protected Overrides Sub OnPaint(...)
'-- e.Graphics.GetToRendering
End Sub
By Trent L. Taylor
-
2/8/2008
One other thought....you may want to use the TextBoxRenderer class to help you generate the standard background, etc instead of manually reinventing the wheel. You can have it draw the standard background to a device context (graphics) so this way you can just render what the text and what you want to add.
By Greg McGuffey
-
2/8/2008
Thanks! I'll look into this.