redrawing panel

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jul 2008
Posts: 27
Reputation: nikola.rosic is an unknown quantity at this point 
Solved Threads: 0
nikola.rosic nikola.rosic is offline Offline
Light Poster

redrawing panel

 
0
  #1
Jan 26th, 2009
I have a panel on form and i'm drawing a graph on it with a pen.When i open something on top of that form or i minimize the form and maximize it, the panel goes white until i draw something on it again.So i think i could call an event when my form goes inactive and active again or when i close anything that i have opened on top of that form.But my problem is that i don't know what should be a trigger for my event.Or if someone knows some better way!!!



Thanks!!!
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 100
Reputation: Clawsy is an unknown quantity at this point 
Solved Threads: 5
Clawsy Clawsy is offline Offline
Junior Poster

Re: redrawing panel

 
0
  #2
Jan 26th, 2009
your description is a little bit confusing but let me guess: trigger the refresh() method for the form:
  1. this.Refresh(); // for immediate redraw of the form and it's components
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 27
Reputation: nikola.rosic is an unknown quantity at this point 
Solved Threads: 0
nikola.rosic nikola.rosic is offline Offline
Light Poster

Re: redrawing panel

 
0
  #3
Jan 26th, 2009
Originally Posted by Clawsy View Post
your description is a little bit confusing but let me guess: trigger the refresh() method for the form:
  1. this.Refresh(); // for immediate redraw of the form and it's components
OK i will do that but you didn't understood what is bodering me.I think i know how to redraw the graph but i don't know how will i know when to do it.I don't know how to tell the code:"OK the graph is beeing disrupted redraw it".

I dont know what to use for triggering the event!!!
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 100
Reputation: Clawsy is an unknown quantity at this point 
Solved Threads: 5
Clawsy Clawsy is offline Offline
Junior Poster

Re: redrawing panel

 
0
  #4
Jan 26th, 2009
for minimize/maximize try AutoSizeChanged event:
  1. private void Form1_AutoSizeChanged(object sender, EventArgs e)
  2. {
  3. this.Refresh();
  4. }
If you open other programs (windows) over the form i know what happenes. you can't do anything for that except 2 things i think:
1) try Activated event for the Focus of the form (because your form is not activated while you use other windows)
2) this really works but i's a little bit complicated. use a thread, BackgroundWorker to Refresh() you pannel. I can't tell the conde right now cause it's a little bit long. The problem is that if the thread refreshes the panel to at very little time intervals, the panel could flicker.

Hope at least one of these solution works.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 100
Reputation: Clawsy is an unknown quantity at this point 
Solved Threads: 5
Clawsy Clawsy is offline Offline
Junior Poster

Re: redrawing panel

 
0
  #5
Jan 26th, 2009
sorry in my post i didn't mean AutoSizeChanged event but SizeChanged event:
  1. private void Form1_SizeChanged(object sender, EventArgs e)
  2. {
  3. this.Refresh();
  4. }
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 21
Reputation: nelis is an unknown quantity at this point 
Solved Threads: 7
nelis nelis is offline Offline
Newbie Poster

Re: redrawing panel

 
0
  #6
Jan 26th, 2009
I'm not sure SizeChanged would fire if the window has just lost focus. I'd try using this.Activated or put an invalidate statement in the Paint event to refresh the graph object.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1,995
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 294
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Posting Virtuoso

Re: redrawing panel

 
0
  #7
Jan 26th, 2009
nelis, think about it.
What would happen if you put an invalidate statement in a Paint event handler?
Yes! It would raise a Paint event, which would call Invalidate which would...
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 21
Reputation: nelis is an unknown quantity at this point 
Solved Threads: 7
nelis nelis is offline Offline
Newbie Poster

Re: redrawing panel

 
1
  #8
Jan 26th, 2009
ddanbe, on the contrary, it wouldn't do an infinite loop like you are suspecting. From your post I'm guessing you're talking about putting a Form.Invalidate(); in the Paint Event, however I didn't suggest doing that. I had stated to invalidate the graphing object. Try it yourself. Create a blank form with a rich textbox. Then do invalidate on the rich textbox.

  1. int x=0;
  2. private void Form1_Paint(object sender, PaintEventArgs e)
  3. {
  4. rtb1.Text += "x: "+(x++)+"\n";
  5. rtb1.Invalidate();
  6. }

You will probably notice that only a few events come through (typically 3) when the form is focused. In my experience, the Paint event is only fired when the form object is painted, not the controls or objects within the form object. For example, if you make the form big and the rich textbox big, drag a small window over the rich textbox. You will notice that the Paint event is not firing. Next while dragging, just slightly move over a section of the form and the Paint event will fire.

This was why I suggested my path. Whatever object the graph is in, invalidate it from the Paint event of the form.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1,995
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 294
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Posting Virtuoso

Re: redrawing panel

 
0
  #9
Jan 26th, 2009
Thanks for enlightning me on the subject. But.
I believe in most of the cases you are right.
Why is it that I get x:44 or x:32 from times to times, when I execute what you said?
I would like to produce the exact circumstances when I got those, (just shuffling windows)
Any ideas?
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 27
Reputation: nikola.rosic is an unknown quantity at this point 
Solved Threads: 0
nikola.rosic nikola.rosic is offline Offline
Light Poster

Re: redrawing panel

 
0
  #10
Jan 27th, 2009
Well thank you all for your help.I will try to test all of your suggestions.I hope it will work
Reply With Quote Quick reply to this message  
Reply

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



Other Threads in the C# Forum
Thread Tools Search this Thread



Tag cloud for C#
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC