A simple start ?

Miura

Active member
Joined
Mar 13, 2003
Messages
27
Hi,

Im new to this Framework, and dont know where to start.
If I would like to show a image from the Harddisk on a form, can
anyone please write some code i VB.Net, so I can get an idea
how to use System.Drawing Namespace.

Thanks,
Lars
 
For a simple request like this you dont have to do any drawing, you can simply assign an Image to the BackgroundImage of the form and it will do the drawing for you. To load a bitmap from disk, you use the constructor for the Bitmap class:

Code:
Dim b As New Bitmap("c:\mybitmap.bmp")
Me.BackgroundImage = b

To draw it yourself, you would skip that second like and keep b around in memory. In the Paint event of the form you would use the DrawImage method of the Graphics class passed to the event under e.
 
Thanks, I have read a little!. But what am I doing wrong.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim GraphicsFun As System.Drawing.Graphics
Dim myBitmap As New Bitmap("D:\Murcielago1.bmp")

GraphicsFun = Me.CreateGraphics
GraphicsFun.DrawImage(myBitmap, 10, 10)

End Sub

Thanks,
Lars.
 
I got this errormessage:

An unhandled exception of type System.ArgumentException occurred in system.drawing.dll

Additional information: Invalid parameter used.
 
That code should work just fine. Are you sure that bitmap exists and is in the correct format?
 
Dont forget to use:
GraphicsFun.Dispose()

after your call to DrawImage(). You must Dispose of the Graphics objects that you create yourself through CreateGraphics(). If you use the Graphics object provided through a Paint event, you do NOT want to call Dispose().

-Nerseus
 
Back
Top