CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    George2 is offline Elite Member Power Poster
    Join Date
    Oct 2002
    Posts
    4,468

    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

  2. #2
    Join Date
    Jul 2006
    Posts
    59

    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

  3. #3
    George2 is offline Elite Member Power Poster
    Join Date
    Oct 2002
    Posts
    4,468

    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


    Quote 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
    }


  4. #4
    Join Date
    Mar 2004
    Location
    33°11'18.10"N 96°45'20.28"W
    Posts
    1,808

    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.

  5. #5
    George2 is offline Elite Member Power Poster
    Join Date
    Oct 2002
    Posts
    4,468

    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?


    Quote 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

  6. #6
    Join Date
    Mar 2004
    Location
    33°11'18.10"N 96°45'20.28"W
    Posts
    1,808

    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.

  7. #7
    Join Date
    Sep 2006
    Location
    Eastern, NC, USA
    Posts
    907

    Re: how to re-draw controls on a Form at a regular interval?

    Quote 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.

  8. #8
    George2 is offline Elite Member Power Poster
    Join Date
    Oct 2002
    Posts
    4,468

    Re: how to re-draw controls on a Form at a regular interval?

    Thank you MadHatter! This is just what I am looking for.


    Quote 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

  9. #9
    George2 is offline Elite Member Power Poster
    Join Date
    Oct 2002
    Posts
    4,468

    Re: how to re-draw controls on a Form at a regular interval?

    I love this hacking way, Pete! Thanks!


    Quote 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
  •  





Click Here to Expand Forum to Full Width

Featured