Drawing over a TextBox in the .NET Compact Framework

Can I use a TextBox control in the .NET Compact Framework? I want to create a watermark over it. I read this answer . This is currently my best approach, but I don't want to limit myself to displaying a watermark only when the TextBox has no focus.

I am ready to try any hack!

0
source share
2 answers

If I did this, I would create a control that comes from a TextBox, so you get all the basic rendering, events, text and selection, yada-yada. Then I P / Invoke in SetWindowLong changed the window handler and processed WM_PAINT in a custom handler, drew a watermark or whatever.

A good base example is the OpenNETCF.Windows.Forms.TextBox2 class, which runs this subclass to handle cut / copy / paste operations. I believe that the code has been there since 1.x days, so the code is freely available (at the bottom of the page in the link above), if you do not / need the latter.

+1
source

Unfortunately, .NET CF TextBox cannot be inherited and used as the basis for this task (OnPaint is not called for starters), so I think that you honestly save time by creating your own control.

Just to get an idea of ​​creating custom controls in .NET CF, if you haven’t already done so, I would highly recommend following this blog post to make the controls transparent as the concept is much the same:

http://christian-helle.blogspot.com/2008/01/transparent-controls-in-netcf.html

If I did this from scratch, I would start by inheriting from the panel and turn it into a text box. The text box is probably one of the most difficult controls to create (especially if the text can be longer than the text box), so you can also see if other vendors have a TextBox component with source code that you could start with, such that way, you could just add .DrawImage to the end of the drawing method and you will have a watermark.

0
source

All Articles