Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Control does not redraw after loosing and regaining focus

Control does not redraw after loosing and regaining focus

Scheduled Pinned Locked Moved C#
csharpbusinesshelpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    uGue
    wrote on last edited by
    #1

    Hi there, C# experts! I have a (in my view actually simple) problem: In my application I want to wait for a predefined timespan and show this to the user via a progress bar. However, I want to call the waiting method from my business logic class rather than from my GUI class. Therefor I use following simple code: public void Wait4Something() { // Timespan we want to wait... int Wtime = 60; // myBar is the progress bar owned by the form. // "this" is NOT the form but a motor class // driving the form and driven by form events. if( this.myBar != null ) { this.myBar.Value = 0; this.myBar.Maximum = Wtime; this.myBar.Step = 1; } this.myGUI.Refresh(); for ( int i = 0; i < Wtime; i += 1 ) { this.SomeOtherObject.Wait4BroadcastReply( (uint) 1000 ); this.myBar.PerformStep(); // Proceed with the progress bar this.myGUI.Refresh(); // <- this does not do apparently } if( this.myBar != null ) this.myBar.Value = 0; } However, if I let the code run, everything is fine until I hit [ALT]-[TAB] to swap windows and then hit it again to swap back to my app. By then, the GUI freezes, shows the hourglass and does not redraw or revalidate and the progress bar does not do steps either. After the specified waiting time, the control returns to normal and reacts to every event as expected. I could probably dissolve the whole thing by starting a new thread, but i hoped not to get forced to do this for a simple visualization of waiting :/ Does anyone know of a feasible solution?? Thanks in advance for your regard, Udo "You can do it that way or that way. I like it that way."

    R 1 Reply Last reply
    0
    • U uGue

      Hi there, C# experts! I have a (in my view actually simple) problem: In my application I want to wait for a predefined timespan and show this to the user via a progress bar. However, I want to call the waiting method from my business logic class rather than from my GUI class. Therefor I use following simple code: public void Wait4Something() { // Timespan we want to wait... int Wtime = 60; // myBar is the progress bar owned by the form. // "this" is NOT the form but a motor class // driving the form and driven by form events. if( this.myBar != null ) { this.myBar.Value = 0; this.myBar.Maximum = Wtime; this.myBar.Step = 1; } this.myGUI.Refresh(); for ( int i = 0; i < Wtime; i += 1 ) { this.SomeOtherObject.Wait4BroadcastReply( (uint) 1000 ); this.myBar.PerformStep(); // Proceed with the progress bar this.myGUI.Refresh(); // <- this does not do apparently } if( this.myBar != null ) this.myBar.Value = 0; } However, if I let the code run, everything is fine until I hit [ALT]-[TAB] to swap windows and then hit it again to swap back to my app. By then, the GUI freezes, shows the hourglass and does not redraw or revalidate and the progress bar does not do steps either. After the specified waiting time, the control returns to normal and reacts to every event as expected. I could probably dissolve the whole thing by starting a new thread, but i hoped not to get forced to do this for a simple visualization of waiting :/ Does anyone know of a feasible solution?? Thanks in advance for your regard, Udo "You can do it that way or that way. I like it that way."

      R Offline
      R Offline
      Robert Rohde
      wrote on last edited by
      #2

      An Application.DoEvents() call instead (or additional) to the Refresh could do the job. But note that you then probably have to disable the form because it will react to user input. A seperate thread would be better...

      U 1 Reply Last reply
      0
      • R Robert Rohde

        An Application.DoEvents() call instead (or additional) to the Refresh could do the job. But note that you then probably have to disable the form because it will react to user input. A seperate thread would be better...

        U Offline
        U Offline
        uGue
        wrote on last edited by
        #3

        Hi Robert, thanks for your instant help, I was afraid of it but in the end it's probably best to do it right in the first place. So I'll be weaving some threads... Thanks, Udo ---- Anyway, Application.DoEvents() did help as a hotfix, and as I'm not doing anything mutual it's probably harmless to let the GUI react to user input, if not wanted. So thanks again for your very helpful advice!

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups