VB.NET Windows App: Hiding Controls During Processing

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    VB.NET Windows App: Hiding Controls During Processing

    This question may seem a bit newbie-ish but I'm new to desktop applications... please bear with me.

    I have a function that populates a ComboBox with a bunch of names.
    To populate it I have to make a function call to an external class library (which is poorly designed) many many times (512 to be exact)....you can see that this will take a while.

    After populating the ComboBox I initialize a user control which displays details about the first selected item.

    Since it takes a couple of seconds to populate the ComboBox before the user control can be loaded I created a function that hides the user control (and any other controls that aren't available until everything's loaded) and display a "loading" message.

    [code=vbnet]
    Private Sub Updating()
    'Centering the message
    Dim x As Integer = theGroupBoxHold ingEveryThingWi dth / 2 - UpdatingMessage .Width / 2
    Dim y As Integer = theGroupBoxHold ingEveryThingWi dth .Height / 2 - UpdatingMessage .Height / 2
    UpdatingMessage .Location = New Point(x, y)

    'Hiding the controls and displaying the message
    thePanelHolding TheControls.Hid e()
    UpdatingMessage .Show()
    End Sub
    [/code]

    I created a function that displays the content and hides the message:
    [code=vbnet]
    Private Sub UpdatingFinishe d()
    'Hiding the message and displaying the controls
    thePanelHolding TheControls.Sho w()
    UpdatingMessage .Hide()
    End Sub
    [/code]

    The problem is that the controls are not hidden and the message is not shown while the processing is going on.

    Originally I was using the Visible property to display updating message and hide the controls but since this didn't work I changed it to the Show() and Hide() methods.

    I've stepped through the application and expected the content to be hidden as soon as the Hide() method was executed but this is not the case.

    Does anyone know why this is happening?

    Thanks for your time,

    -Frinny
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Be sure to call the .Update() function on any gui object that you changed.

    Whats roughly happening is:
    You set the controls hidden, but before it has time to process the windows message for it, your program gets busy gathering values. When it stops being busy, it will process the messages, but since right after the "hide" message is probably a "show" message, you don't see a change.

    What the Update() call does, is force the program to process the windows messages for that control(and child controls too I think), if you wanted it to process all windows messages in the queue, you would use Application.DoE vents()

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      Originally posted by Plater
      Be sure to call the .Update() function on any gui object that you changed.

      Whats roughly happening is:
      You set the controls hidden, but before it has time to process the windows message for it, your program gets busy gathering values. When it stops being busy, it will process the messages, but since right after the "hide" message is probably a "show" message, you don't see a change.

      What the Update() call does, is force the program to process the windows messages for that control(and child controls too I think), if you wanted it to process all windows messages in the queue, you would use Application.DoE vents()
      Thanks Plater!

      The Control.Update method executes any pending requests for "painting". Since everything was within the the group box (theGroupBoxHol dingEveryThing) I only had to call the Update method on that group box.

      :) This is going to fix a bunch of problems I was having with my other controls :)

      -Frinny

      Comment

      Working...