PaintPicture -- How??

A

Anagnos

I recently got VB.NET, and now I need to somehow use the PaintPicture
command from VB6. Obviously it does not exist in .NET. I would do this
in 6 but I need to use pngs as images, because only they support
semi-transparent pixels.

Thanks in advance,
 
A

Andrew Gaubatz

The help says that you can use the drawimage but i'd rather not have it
as an event, is there anyway to just use a line of code for it? Or even
a way to call on the PaintEventArgs event?
 
K

Ken Tucker [MVP]

Hi,

Try something like this.

Dim g as graphics = picturebox1.creategraphics

Ken
 
A

Andrew Gaubatz

Thanks,

Unfortunatly this still does not work, the form loads fine but nothing
happens. here is my code:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim g As Graphics = PictureBox1.CreateGraphics


PictureBox1.CreateGraphics.DrawImage(System.Drawing.Image.FromFile("C:\D
ocuments and Settings\Telemachus\Desktop\1.png"), 1, 1)

End Sub
 
K

Ken Tucker [MVP]

Hi,

The load event occurs before the paint event. So the paint
event erases the stuff drawn in the load event. If you want the picturebox
to redraw itself set the picturebox image property.

PictureBox1.image = Image.FromFile("C:\Documents and
Settings\Telemachus\Desktop\1.png")

Ken
--------------------------
Thanks,

Unfortunatly this still does not work, the form loads fine but nothing
happens. here is my code:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim g As Graphics = PictureBox1.CreateGraphics


PictureBox1.CreateGraphics.DrawImage(System.Drawing.Image.FromFile("C:\D
ocuments and Settings\Telemachus\Desktop\1.png"), 1, 1)

End Sub
 
A

Andrew Gaubatz

Thanks, I got it working just by delaying the code with a timer. Thanks
again.
 
A

Andrew Gaubatz

Thanks, that works but I am going to end up needing to have multiple
images in the picture box. Any way to do that?
 
J

Jeff Johnson [MVP: VB]

Thanks, I got it working just by delaying the code with a timer. Thanks
again.

Use the Paint event of the picture box. Every time the picture box needs
updating it will fire this event and then you draw your picture(s).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top