|
-
Apr 28th, 2004, 02:57 PM
#1
Thread Starter
Frenzied Member
Persisting Graphics{Resolved}
I have a project I've been working on and it consists of working with graphics.
The only problem I have is when the graphics show up on the form; if I minimize it or another window comes over top of my projects form, it erases the graphics.
I know I might of not explained this well enough or it might not make sense but I'm not sure how to explain it. So Can anyone please give me a solution?
Also I posted in the other forum and got an answer in VB6 when i need it in VB.NET
anyways they said that the auto redraw property of the form should be set to true.
What would the auto redraw property of a form be in VB.NET?
Last edited by System_Error; Apr 28th, 2004 at 05:29 PM.
-
Apr 28th, 2004, 03:40 PM
#2
Hi.
There is no autoredraw in NET...
If you're painting directly on the form, using the CreateGraphics then that's why your graphics disappear. That is only drawn to the surface once, so it will be removed on the next redraw.
To keep the graphics, you need to paint it in the Paint event of the form (or whatever object you're drawing on). Then draw to e.Graphics.
I wish I could think of something witty to put in my sig...
...Currently using VS2013...
-
Apr 28th, 2004, 03:46 PM
#3
Draw the graphics onto a bitmap object. And then set the form's image property = the bitmap.
Et voila, persistent graphics.
It took me ages to work out how to do that and I hated .net because it had no autoredraw. But it actually promotes better programming practices imo.
I don't live here any more.
-
Apr 28th, 2004, 05:29 PM
#4
Thread Starter
Frenzied Member
Thanx. That was a huge help.
-
Dec 5th, 2005, 09:04 PM
#5
Fanatic Member
Re: Persisting Graphics{Resolved}
Draw the graphics onto a bitmap object. And then set the form's image property = the bitmap.
got samples?
man, I got the same problem, me brain's about to blow!

edit: got everything fixed up... but I don't have as much flexibility over doing graphics...
can't draw a string directly to the bitmap...
Last edited by Ruku; Dec 5th, 2005 at 09:43 PM.
-
Dec 5th, 2005, 10:16 PM
#6
Re: Persisting Graphics{Resolved}
VB Code:
Dim bm As New Bitmap(Me.Size.Width, Me.Size.Height)
Dim gr As Graphics
gr = Graphics.FromImage(bm)
gr.FillRectangle(SystemBrushes.Control, 0, 0, Me.Size.Width, Me.Size.Height)
gr.DrawEllipse(Pens.Black, 0, 0, 100, 50)
Me.BackgroundImage = bm
The fillREct is there so you don't have a transparent background on repaint..
Bill
-
Dec 5th, 2005, 10:24 PM
#7
Re: Persisting Graphics{Resolved}
 Originally Posted by Ruku
can't draw a string directly to the bitmap... 
Wouldn't you just call the DrawString method of the Graphics object?
-
Dec 5th, 2005, 10:35 PM
#8
Re: Persisting Graphics{Resolved}
He's right, the DrawString method will do just that, however, if you are wanting the app to have the look and feel of the rest of the OS, you can run into much more code. You'll need to take into consideration the size and style of fonts being used by the user in order to do this well. You can get the font as easily as using Me.Font inside your form class, and the dimensions of the finished product by using the MeasureString method, though some have mentioned certain characters don't measure correctly.
Bill
-
Dec 12th, 2005, 05:17 PM
#9
Fanatic Member
Re: Persisting Graphics{Resolved}
yeah, I got everything fixed up! I figured how to use the graphics object onto the bitmap object...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|