Invalidate picturebox with rectangle on

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2008
Posts: 7
Reputation: Dumpen1337 is an unknown quantity at this point 
Solved Threads: 0
Dumpen1337 Dumpen1337 is offline Offline
Newbie Poster

Invalidate picturebox with rectangle on

 
0
  #1
Apr 6th, 2008
Hello.

I have a simple picturebox where there is a image loaded in

Im drawing a rectangle on the picturebox and when I press a button I want to invalidate it (remove the rectangle), but it doesnt seem to work

The rectangle is drawn fine and the image loads up to, but when I press my button nothing happens

Here is the code im using:
  1. private void drawOnPic()
  2. {
  3. // Attach grapich to picturebox
  4. Graphics g = Graphics.FromImage(pictureBox1.Image);
  5.  
  6. // Create a new pen that we shall use for drawing the line
  7. Pen PenStyle = new Pen(Color.Red, 1);
  8.  
  9. // Draw a 50x50 pixels rectangle (x, y, width, hight)
  10. g.DrawRectangle(PenStyle, 20, 20, 50, 50);
  11. }
  12.  
  13. private void button1_Click(object sender, EventArgs e)
  14. {
  15. pictureBox1.Invalidate();
  16. }
  17.  
  18. private void Form1_Load(object sender, EventArgs e)
  19. {
  20. drawOnPic();
  21. }
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
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