Groups | Blog | Home
all groups > dotnet drawing api > may 2005 >

dotnet drawing api : onPaint handler


YYZ
5/25/2005 11:13:31 AM
Is there anyway to get an onPaint handler for a textbox?

In VB 6 I would subclass the control (never done it with a textbox, but I
think it would have worked), but I don't think I can do that here in .Net.

Matt

Bob Powell [MVP]
5/26/2005 12:00:00 AM
The TextBox loosely wraps the Win32 TextBox and so is pretty well set in
it's ways. I have seen numerous textbox re-implementations in C# or VB that
were designed to overcome those shortcomings that TextBox has.

Perhaps you need a custom control...

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





[quoted text, click to view]

Bob Powell [MVP]
5/27/2005 12:00:00 AM
Do you have to edit the text in the box or is it just a fat label?

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





[quoted text, click to view]

YYZ
5/27/2005 1:29:13 PM

[quoted text, click to view]

Not to be lazy, but can you give me some keywords to search on? I'm at a
loss, honestly.

[quoted text, click to view]

Yes I do. All I really want to do is to put an image inside the textbox
that is on the background. It's a little icon, 16x16, that is supposed to
float and stay at the right/top of a textbox, if it is multilined or not,
and the text in the control can appear over the top of it.

Any ideas on how to create a custom control to do what I want?

Thanks for any advice you have.

Matt

YYZ
5/28/2005 7:39:54 PM
[quoted text, click to view]

I wish. Yes, the text will have to be editable.

Our company is just starting our first development in .Net -- we have
previously used a textbox and a command button with a magnifying glass image
on it to indicate to our users that they can type in a labor element code or
some other type of code, or they can click on the "zoom" button to see a
list -- the list may have up to 10,000 items in it, so the list needs to be
a screen with filtering options, etc.

In our new development, we want to get rid of a lot of the screen clutter.
One option we are investigating is creating a textbox with an image on the
right edge of it, but still inside the edit portion of the control.
Ideally, the text would appear OVER the image if the text was that long.

I've written a usercontrol that just wraps the textbox control and has a
picturebox, but the text doesn't appear over the top, of course.

Matt

YYZ
5/29/2005 12:21:17 AM

[quoted text, click to view]

In trying to get this done, I have TRIED the following, but can't figure out
why it won't work. I created a new standard windows form project
(VB.net) -- I then added in a project for an inherited usercontrol. I then
immediately went into this usercontrol's code editor and changed its inherit
line to this:
Inherits System.Windows.Forms.TextBox

This is very nice, as when I add the usercontol onto my test form in the
other project, it acts just like a usercontrol.

Now, I want to override the onPaint or onPaintBackground funtionality (is
this an event, a method, ??) -- I have added this code:

Protected Overrides Sub OnPaint(ByVal e As
System.Windows.Forms.PaintEventArgs)
Debug.WriteLine("OnPaint")
MyBase.OnPaint(e)
End Sub

But I never get a debug statement printed. I also added this (just for
testing)

Protected Overrides Sub OnMouseEnter(ByVal e As System.EventArgs)
Debug.WriteLine("OnMouseEnter")
MyBase.OnMouseEnter(e)
End Sub

And I DO get debug statements. So, either I'm not understanding how the
onPaint thing works, or I'm just flat out trying to implement it
incorrectly, or both.

Any ideas from anyone out there?

Once I DO figure out how to get the paint stuff plugged in, then I'll worry
about drawing my image in teh correct place. After that I'll worry about
adding in a new event, etc. But first, I've got to figure out how to draw
what I want.

Thanks to anyone out there for any advice, pointers, articles, etc.

Matt

SharpCoderMP
6/2/2005 12:00:00 AM
[quoted text, click to view]

instead of looking for debug meseges, just try to draw something on your
control inside OnPaint(...)
it seems that this Debug.WriteLine("...") does not work always as you'd
expect. i had some problems with this too.

oh, and maybe it would be better to create custom control (not inherited
control) and just add to it one text box and expose it's methods that
you need. then all you need is to add PictureBox with your image on top
of this text box.

YYZ
6/5/2005 9:02:00 PM

[quoted text, click to view]

I did try that first, and wasn't seeing anything, so I added in the debug
statements to see if my code was being executed, and if so, when. I took it
all out when I posted here to keep it short.

[quoted text, click to view]

I havne't used .Net much, so I bet you are right. I'll have to read up on
this.

[quoted text, click to view]

I did do that, actually. I, just for testing exposed the whole textbox
itself instead of figuring out how to pass through ALL properties and
methods. And I put the picturebox on there, too, but it appears on TOP of
the textbox, not behind it...meaning, I can't make the background of the
textbox be transparent unfortunately. That's why I'm trying to do it this
way now, by inheriting the textbox itself.

Thanks for the advice, though!

Matt

SharpCoderMP
6/11/2005 12:00:00 AM
i did some tests...
well, i don't know why, but it looks like textBox NEVER fires
OnPaint(...) event!
i have no idea why. i did this:
created customcontrol
inherited from System.Windows.Forms.TextBox
inside protected override void OnPaint(...) did some painting

when i run app with this custom controll i get nice ORYGINAL textbox but
when i run a debugger... well it never enteres OnPaint(...) method of my
custom controll!

i do not have idea what is going on here.
any ideas from gurus?
or maybe textBox is not painted?? maybe it just... appears on the screen
in some magical way?



[quoted text, click to view]
AddThis Social Bookmark Button