Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Draw PNG-image on the form
 

Draw PNG-image on the form

I'm using VB.net (.Net 2.0). How to draw a png image file on the form by clicking a button? I would like to set the cordinates (x, y) but the image size should be the original of the file. I would like to view the png files as transparent (as they originally are).
re infecta  Wednesday, September 27, 2006 8:15 PM
When clicking the button set a global boolean to true (i.e LoadImage), then call Me.Refresh().
On your form event called Paint do the following

Private Sub frmMaint_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
if (LoadImage = True) then
e.Graphics.DrawImage("C:\myimage.png", New Point(100, 200))
end if
End Sub


Untested, should work.

Regards,

Luc Pettett
Luc Pettett  Friday, September 29, 2006 5:44 AM
I didn't really optimise that code.. you probably should load the image into memory prior to the refresh event.

Luc Pettett
Luc Pettett  Friday, September 29, 2006 5:46 AM
Thanks! I have loaded the images as resources. How to make reference to them? I think it's not very handy to refer every time to particular path on hard disk.
re infecta  Saturday, September 30, 2006 11:00 PM

Hello,

If you have added the file as an embedded resource project can do the following:

Dim myImage as new Bitmap(Assembly.GetExecutingAssembly().
GetManifestResourceStream("PictureBoxControl.myimage.png"))

and keep this 'myImage' vairable as public so you don't need to reload it.

To make it simple I would just add a picture box to your form and when you want to see the png image just set the picture box Visible to True.

Enjoy,

Luc Pettett

Luc Pettett  Monday, October 02, 2006 11:18 PM

You can use google to search for other answers

Custom Search

More Threads

• How does the designer locate an assembly ?
• "Select Resource" Dialog not appearing when in Design Mode.
• VS 2005 Winform designer Issue
• Name Property
• Designer calling the Form Load event of Base Form...
• custom DataGridView AllowUserToOrderColumns property
• How to make a copy of a Form?
• How to Implement an Event Binding Service?
• ideas for composite control (is this possible?)
• Calender Control to View Data by Date, Weekly , Monthly