retaining graphics

Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Dec 2008
Posts: 6
Reputation: dthree is an unknown quantity at this point 
Solved Threads: 0
dthree dthree is offline Offline
Newbie Poster

retaining graphics

 
0
  #1
Jan 7th, 2009
hi folks,
I'm writing a program for a punch press that displays the pattern to be punched. I have learned how to retrieve the data from a spreadsheet calculate the hole angles and draw them on my form
  1. { Using g As Graphics = Me.CreateGraphics
  2. Dim pn As New Pen(Color.Crimson, 3)
  3. Dim circ As New Rectangle((xdrawloc), (ydrawloc), 12, 12)
  4. g.DrawEllipse(pn, circ)
  5.  
  6. xloc.Add(xdrawloc)
  7. yloc.Add(ydrawloc)
  8. End Using}
The basic pattern has multiple holes and is different for each process. As the machine runs it fills in the holes and changes colors.

My problem is when the form is minimized and then reopened all the graphics are gone. If the program is running then it keeps adding drawings to the screen but the prior screen drawings have been erased. How do i retain all the drawings that are getting placed on the screen when it is minimized. It's probably an asy answer but i'm new and going in the circles i'm trying to draw.
Last edited by Ancient Dragon; Jan 8th, 2009 at 8:56 pm. Reason: add code tags
Reply With Quote Quick reply to this message  
Join Date: Dec 2002
Posts: 461
Reputation: waynespangler is on a distinguished road 
Solved Threads: 56
waynespangler waynespangler is offline Offline
Posting Pro in Training

Re: retaining graphics

 
0
  #2
Jan 7th, 2009
Instead of using the form graphics use a bitmap and set the form background equal to the bitmap image. Now when you write to the bitmap it will be transfered automatically to the form background image. Otherwise you have to do all your drawing in the form paint event and call Form.Invalidate.
Wayne

It is hard to understand how a cemetery can raise its burial rates and blame it on the cost of living.
Reply With Quote Quick reply to this message  
Join Date: Dec 2002
Posts: 461
Reputation: waynespangler is on a distinguished road 
Solved Threads: 56
waynespangler waynespangler is offline Offline
Posting Pro in Training

Re: retaining graphics

 
0
  #3
Jan 7th, 2009
create a new project and add this code. Start it with the window minimized.
  1. Public Class Form1
  2. Private bmp As Bitmap = New Bitmap(100, 200, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
  3. Private gr As Graphics = Graphics.FromImage(bmp)
  4.  
  5. Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  6. Me.BackgroundImageLayout = ImageLayout.None
  7. Me.BackgroundImage = bmp
  8. gr.FillEllipse(Brushes.Blue, New Rectangle(0, 0, 100, 200))
  9. End Sub
  10.  
  11. End Class
Wayne

It is hard to understand how a cemetery can raise its burial rates and blame it on the cost of living.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 6
Reputation: dthree is an unknown quantity at this point 
Solved Threads: 0
dthree dthree is offline Offline
Newbie Poster

Re: retaining graphics

 
0
  #4
Jan 7th, 2009
Thanks,Wayne
I'll give it a try. It's a very dynamic drawing containing up to 600 circle targets for several hundred different patterns. The code I have already wrote works so well until you minimize it then poof it's all gone. I guess it's part of the learning process. Your code did make the lights come on though and i can't wait to see the results. I'll hack on it some more tomorrow. Love west Virginia by the way spend a lot of time up at Cass, my wife and I are steam engine railroad fans
Reply With Quote Quick reply to this message  
Join Date: Dec 2002
Posts: 461
Reputation: waynespangler is on a distinguished road 
Solved Threads: 56
waynespangler waynespangler is offline Offline
Posting Pro in Training

Re: retaining graphics

 
0
  #5
Jan 7th, 2009
Yea, love Cass myself. This summer we are going to take the Mistery Train ride and see if I'm smart enought to solve the crime. I was away from West Virginia for 40 years and now I will never leave it again.

You might be able to put the code in Form.Paint but I think it will slow up your drawing because you have to keep drawing everything. With the bitmap you draw to it once and keep adding more. You don't need to draw anything you already drew.

If you can convert to drawing to bitmap I think in the long run it would be worth your extra time.
Last edited by waynespangler; Jan 7th, 2009 at 6:40 pm. Reason: can't spell
Wayne

It is hard to understand how a cemetery can raise its burial rates and blame it on the cost of living.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 6
Reputation: dthree is an unknown quantity at this point 
Solved Threads: 0
dthree dthree is offline Offline
Newbie Poster

Re: retaining graphics

 
0
  #6
Jan 8th, 2009
Got it!!!

Thanks for your help, ended up using a picturebox instead of writing on the form but it does retain it now that it is a bitmap and using the picturebox helped keep everything in order when changing aspect ratios. Now i've got to start integrating it to the machine. OPC time, back to the books. thanks again!!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC