Click to See Complete Forum and Search --> : how to re-draw controls on a Form at a regular interval?


George2
November 26th, 2006, 08:34 AM
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

hedge_fund
November 26th, 2006, 08:30 PM
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


foreach(Form frm in Application.OpenForms)
{
if(frm.Visible)
{
//do whatever you need here
}
}

George2
December 5th, 2006, 12:47 AM
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


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


foreach(Form frm in Application.OpenForms)
{
if(frm.Visible)
{
//do whatever you need here
}
}

MadHatter
December 5th, 2006, 01:57 AM
rule # 1: always do custom drawing in your Paint method. this way your painting is done w/ every repaint of the form.

George2
December 5th, 2006, 03:38 AM
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?


rule # 1: always do custom drawing in your Paint method. this way your painting is done w/ every repaint of the form.


regards,
George

MadHatter
December 5th, 2006, 09:08 AM
only visible forms are painted. if the users uses form1 then put custom drawing for form 1 in form1's OnPaint override.

petes1234
December 5th, 2006, 05:07 PM
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

George2
December 6th, 2006, 07:55 AM
Thank you MadHatter! This is just what I am looking for.


only visible forms are painted. if the users uses form1 then put custom drawing for form 1 in form1's OnPaint override.


regards,
George

George2
December 6th, 2006, 07:59 AM
I love this hacking way, Pete! Thanks! :thumb: ;)


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