Miura Posted March 13, 2003 Posted March 13, 2003 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 Quote
*Gurus* divil Posted March 14, 2003 *Gurus* Posted March 14, 2003 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. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
mooman_fl Posted March 15, 2003 Posted March 15, 2003 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. Quote "Programmers are tools for converting caffeine into code." Madcow Inventions -- Software for the Sanity Challenged.
Miura Posted March 16, 2003 Author Posted March 16, 2003 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. Quote
Miura Posted March 16, 2003 Author Posted March 16, 2003 I got this errormessage: An unhandled exception of type 'System.ArgumentException' occurred in system.drawing.dll Additional information: Invalid parameter used. Quote
*Gurus* divil Posted March 17, 2003 *Gurus* Posted March 17, 2003 That code should work just fine. Are you sure that bitmap exists and is in the correct format? Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Miura Posted March 17, 2003 Author Posted March 17, 2003 I have fixed the problem now. Thanks a lot, and have a nice day. Quote
*Experts* Nerseus Posted March 17, 2003 *Experts* Posted March 17, 2003 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 Quote "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
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.