|
-
Jun 30th, 2022, 11:00 PM
#5
Re: Showing text over an image
Firstly, that code is not valid. Secondly, if you change it to be valid then it will work as you want.
If you had spent a bit more time researching AddHandler then you'd know that the statement follows this format:
vb.net Code:
AddHandler TheObject.TheEvent, AddressOf TheMethod
If you want to handle the Paint event of pb1 then Paint is TheEvent and pb1 is TheObject.
You probably don't need to use AddHandler at all though, because you probably don't need to create a control at run time. Is there a good reason that you're not just adding this PictureBox to the form in the designer? There may be but I'm not seeing evidence of it here. If you create the control at run time then you have no choice but to use AddHandler to attach an event handler but if you add the control in the designer then you can use WithEvents/Handles. In that case, you can use the Properties window or the Navigation Bar in the code window to generate and attach the event handler.
On the subject of using the Paint event for GDI+ drawing, you should include the code to draw the text in the Paint event handler and then, when you want to change the text, call the Invalidate method of the PictureBox and specify the smallest area you can that incorporates the text. You don't have to specify an area but then the whole area will get repainted. That is not necessarily a problem but can lead to flickering, as the repainting process is relatively slow.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|