|
-
November 26th, 2006, 09:34 AM
#1
how to re-draw controls on a Form at a regular interval?
Hello everyone,
I am using C# on a Pocket PC 2003 project based on .Net Compact Framework of Visual Studio 2005. I want to re-draw some controls of a Form (Window) at a regular interval (for example, change the title of some Label or something similar). The issues I met with are,
1. My application has several Forms/Windows. How to check whether the specific Form/Window (which I want to re-draw) is active? If the Form/Window is not active, I think I should not re-draw the Form/Window. Am I correct? Or, whether or not the Form/Window is active, I should always re-draw the Form/Window?
2. Any code samples specific for C# of .Net Compact Framework?
thanks in advance,
George
-
November 26th, 2006, 09:30 PM
#2
Re: how to re-draw controls on a Form at a regular interval?
George,
When you are developing for the mobile platform, you can only have one active (visible) form at a time per application so I am not sure why you would like to redraw more than one form at a time. With that aside, there is a property for the Application object called OpenForms. You can use a timer and everytime the timer fires the notification event, you can loop through all the Form objects in OpenForms and check if each is visible and if it is, you can perform whatever operation you need on it.
Here's a quick example
PHP Code:
foreach(Form frm in Application.OpenForms) { if(frm.Visible) { //do whatever you need here } }
If my posts have helped you, please rate them. Ratings give me that warm, fuzzy feeling of having helped someone out 
-
December 5th, 2006, 01:47 AM
#3
Re: how to re-draw controls on a Form at a regular interval?
Thank you hedge_fund! I want to dynamically display something on a Form, for example, display current hour, display how many new messages have been arrived from server, something like this.
I want to re-draw the user interface automatically (like WEB 2.0) other than let user click some button to manually re-draw. Do you have any comments or suggestions to my idea? Any more comprehensive samples to refer? :-)
regards,
George
 Originally Posted by hedge_fund
George,
When you are developing for the mobile platform, you can only have one active (visible) form at a time per application so I am not sure why you would like to redraw more than one form at a time. With that aside, there is a property for the Application object called OpenForms. You can use a timer and everytime the timer fires the notification event, you can loop through all the Form objects in OpenForms and check if each is visible and if it is, you can perform whatever operation you need on it.
Here's a quick example
PHP Code:
foreach(Form frm in Application.OpenForms)
{
if(frm.Visible)
{
//do whatever you need here
}
}
-
December 5th, 2006, 02:57 AM
#4
Re: how to re-draw controls on a Form at a regular interval?
rule # 1: always do custom drawing in your Paint method. this way your painting is done w/ every repaint of the form.
-
December 5th, 2006, 04:38 AM
#5
Re: how to re-draw controls on a Form at a regular interval?
Thanks MadHatter! In your method, there is an issue. Suppose user always uses Form1, since paint method will only be invoked when it is activated, the elements of the Form 1 will never be re-drawn. Right?
 Originally Posted by MadHatter
rule # 1: always do custom drawing in your Paint method. this way your painting is done w/ every repaint of the form.
regards,
George
-
December 5th, 2006, 10:08 AM
#6
Re: how to re-draw controls on a Form at a regular interval?
only visible forms are painted. if the users uses form1 then put custom drawing for form 1 in form1's OnPaint override.
-
December 5th, 2006, 06:07 PM
#7
Re: how to re-draw controls on a Form at a regular interval?
 Originally Posted by George2
Suppose user always uses Form1, since paint method will only be invoked when it is activated, the elements of the Form 1 will never be re-drawn. Right?
I think that you can call the "invalidate()" method for the form from within the .NET compact framework. Have you tried calling this from within your timer event to trigger the form's paint event and force a redraw?
/Pete
Last edited by petes1234; December 5th, 2006 at 06:09 PM.
-
December 6th, 2006, 08:55 AM
#8
Re: how to re-draw controls on a Form at a regular interval?
Thank you MadHatter! This is just what I am looking for.
 Originally Posted by MadHatter
only visible forms are painted. if the users uses form1 then put custom drawing for form 1 in form1's OnPaint override.
regards,
George
-
December 6th, 2006, 08:59 AM
#9
Re: how to re-draw controls on a Form at a regular interval?
I love this hacking way, Pete! Thanks!
 Originally Posted by petes1234
I think that you can call the "invalidate()" method for the form from within the .NET compact framework. Have you tried calling this from within your timer event to trigger the form's paint event and force a redraw?
/Pete
regards,
George
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
|