Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi,

 

I'm new to this Framework, and don't 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

  • *Gurus*
Posted

For a simple request like this you don't 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:

 

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.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted

If you want a good set of tutorials with lots of basic code on GDI+ then try this page:

 

http://www.informit.com/content/index.asp?product_id=%7B00C5C1E2-C529-441E-882D-FCF15A71B7F8%7D

 

Read it thoroughly and actually use the example code and study it. It is really helpful in picking up this subject. They do what you were asking about (displaying bitmaps on forms) but that is handled somwhere in the neighborhood of chapter 5 or 6.

"Programmers are tools for converting caffeine into code."

 

Madcow Inventions -- Software for the Sanity Challenged.

Posted

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.

Posted

I got this errormessage:

 

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

 

Additional information: Invalid parameter used.

  • *Experts*
Posted

Don't 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

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...