943,600 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Marked Solved
  • Views: 8597
  • C# RSS
You are currently viewing page 1 of this multi-page discussion thread
Jan 26th, 2009
0

redrawing panel

Expand Post »
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!!!
Reputation Points: 10
Solved Threads: 0
Light Poster
nikola.rosic is offline Offline
27 posts
since Jul 2008
Jan 26th, 2009
0

Re: redrawing panel

your description is a little bit confusing but let me guess: trigger the refresh() method for the form:
C# Syntax (Toggle Plain Text)
  1. this.Refresh(); // for immediate redraw of the form and it's components
Reputation Points: 11
Solved Threads: 7
Posting Whiz in Training
Clawsy is offline Offline
225 posts
since Feb 2008
Jan 26th, 2009
0

Re: redrawing panel

Click to Expand / Collapse  Quote originally posted by Clawsy ...
your description is a little bit confusing but let me guess: trigger the refresh() method for the form:
C# Syntax (Toggle Plain Text)
  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!!!
Reputation Points: 10
Solved Threads: 0
Light Poster
nikola.rosic is offline Offline
27 posts
since Jul 2008
Jan 26th, 2009
0

Re: redrawing panel

for minimize/maximize try AutoSizeChanged event:
C# Syntax (Toggle Plain Text)
  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.
Reputation Points: 11
Solved Threads: 7
Posting Whiz in Training
Clawsy is offline Offline
225 posts
since Feb 2008
Jan 26th, 2009
0

Re: redrawing panel

sorry in my post i didn't mean AutoSizeChanged event but SizeChanged event:
C# Syntax (Toggle Plain Text)
  1. private void Form1_SizeChanged(object sender, EventArgs e)
  2. {
  3. this.Refresh();
  4. }
Reputation Points: 11
Solved Threads: 7
Posting Whiz in Training
Clawsy is offline Offline
225 posts
since Feb 2008
Jan 26th, 2009
0

Re: redrawing panel

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.
Reputation Points: 15
Solved Threads: 7
Newbie Poster
nelis is offline Offline
21 posts
since Jan 2009
Jan 26th, 2009
0

Re: redrawing panel

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...
Reputation Points: 2023
Solved Threads: 644
Senior Poster
ddanbe is offline Offline
3,735 posts
since Oct 2008
Jan 26th, 2009
1

Re: redrawing panel

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.

C# Syntax (Toggle Plain Text)
  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.
Reputation Points: 15
Solved Threads: 7
Newbie Poster
nelis is offline Offline
21 posts
since Jan 2009
Jan 26th, 2009
0

Re: redrawing panel

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?
Reputation Points: 2023
Solved Threads: 644
Senior Poster
ddanbe is offline Offline
3,735 posts
since Oct 2008
Jan 27th, 2009
0

Re: redrawing panel

Well thank you all for your help.I will try to test all of your suggestions.I hope it will work
Reputation Points: 10
Solved Threads: 0
Light Poster
nikola.rosic is offline Offline
27 posts
since Jul 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Config.xml
Next Thread in C# Forum Timeline: Advantages of C# over C++





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC