Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2841
  • Last Modified:

Refresh Winforms control c#

Hi

A little new to c# winforms programming

I have a form that has a Text Control that I want to display some text then wait clear it out and loop to the next values

I have something like this

          do
            {

             txtList.Text = "A bunch of text";
   .....
   .....  // More text is displayed
   .....
                System.Threading.Thread.Sleep(10000); // wait then clear text
                txtList.Text = "";

           } while (iPos > 0);  


Everything works fine except the displaying. It seems to wait until everything is done. How can I get the textbox to refresh while the data is building then do the next iteration of text display?

Thanks
Chuck
0
Charles Baldo
Asked:
Charles Baldo
  • 2
2 Solutions
 
TheMozzCommented:
You may consider using a Timer control instead. You could use the Timer_Tick event to do data processing and updating on your form.

What are you displaying in that text box as the loop executes?
0
 
John ClaesCommented:
Adding a Timer and using the Timer_Tick function the form is drawn
The Timer then ticks in a other thread and will change the values in your form (thread) and so the form will be redrawn.

So indeed, use a Timer and put you're text-swapping-Changes in the Timer_tick event.
0
 
TheMozzCommented:
One other quick thing, as you add text to the textbox, you'll need to tell the textbox to refresh it's display:

this.txtList.Refresh();

And then call Application.DoEvents() to allow the operating system to do the drawing of the screen. That is why it waits to refresh the display.
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now