Tech Off Thread

7 posts

Form.Text does not update

Back to Forum: Tech Off
  • User profile image
    ploe

    I have this one window where when I set the Text property of the Form it does not update the title bar. I am 100% sure my code is being called and the Text value is being changed. It's just not physically painting it on the screen.

     

    I have about 100 or so Forms and this is the only Form that does this. I've compared properties with a window that does work and can't see anything odd that I'm doing in the broken Form. Has anyone run accross this or have an idea of things I can check?

  • User profile image
    IDWMaster

    How are you updating the value; could you post some of your code?

  • User profile image
    W3bbo

    • Is the .Text property being set on the same thread that instantiated the form?
    • Set a breakpoint to make sure it's been hit
    • Make a copy of your form's code and reduce it down until you get the smallest amount of code that reproduces the problem, then compare it to a working sample.

  • User profile image
    ploe

    W3bbo said:
    • Is the .Text property being set on the same thread that instantiated the form?
    • Set a breakpoint to make sure it's been hit
    • Make a copy of your form's code and reduce it down until you get the smallest amount of code that reproduces the problem, then compare it to a working sample.

    I can't seem to find a different between the windows.

     

    I have a method called UpdateTitle() that actually updates the Form's Text. InvokeRequired always returns false, so it's definately not in the wrong Thread. Nothing related to this window is multi-threaded so this was not surprising.

     

    When I put in a breakpoint, the title does update. I suspect that's because Visual Studio takes focus and when I go back to the window, it triggers a re-paint of the non-client area. The title change also shows up if I minimize, then maximize the window.

  • User profile image
    W3bbo

    ploe said:
    W3bbo said:
    *snip*

    I can't seem to find a different between the windows.

     

    I have a method called UpdateTitle() that actually updates the Form's Text. InvokeRequired always returns false, so it's definately not in the wrong Thread. Nothing related to this window is multi-threaded so this was not surprising.

     

    When I put in a breakpoint, the title does update. I suspect that's because Visual Studio takes focus and when I go back to the window, it triggers a re-paint of the non-client area. The title change also shows up if I minimize, then maximize the window.

    Can you post your code?

  • User profile image
    ploe

    W3bbo said:
    ploe said:
    *snip*

    Can you post your code?

    I'm an idiot. I couldn't find the bug because it wasn't in the window's code, but our base class that it extends. The other windows where the title update does work inherits a different base class.

     

    In our base class we disabled painting while the window was in a state of populating data (because we were getting flicker) with this line:

    SendMessage(this.Handle, WM_SETREDRAW, 0, IntPtr.Zero);

     

    We re-enabled painting when it is done populating with this line:

    SendMessage(this.Handle, WM_SETREDRAW, 1, IntPtr.Zero);

     

    Then we call Invalidate(true). But that just invalidates the client area, not the non-client area, hence why the title bar was not re-painting.

     

    Solution:

    Invalidate and paint the ENTIRE window by calling: InvalidateRect() and then UpdateWindow().

     

    Sorry for the wild goose chase.

  • User profile image
    W3bbo

    ploe said:
    W3bbo said:
    *snip*

    I'm an idiot. I couldn't find the bug because it wasn't in the window's code, but our base class that it extends. The other windows where the title update does work inherits a different base class.

     

    In our base class we disabled painting while the window was in a state of populating data (because we were getting flicker) with this line:

    SendMessage(this.Handle, WM_SETREDRAW, 0, IntPtr.Zero);

     

    We re-enabled painting when it is done populating with this line:

    SendMessage(this.Handle, WM_SETREDRAW, 1, IntPtr.Zero);

     

    Then we call Invalidate(true). But that just invalidates the client area, not the non-client area, hence why the title bar was not re-painting.

     

    Solution:

    Invalidate and paint the ENTIRE window by calling: InvalidateRect() and then UpdateWindow().

     

    Sorry for the wild goose chase.

    If you're getting flickering just enable double-buffering. Disabling painting whilst populating just feels like a bad move.

Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.