Solved

Refresh Winforms control c#

Posted on 2011-02-17
3
2,532 Views
Last Modified: 2013-12-17
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
Comment
Question by:charlesbaldo
  • 2
3 Comments
 
LVL 8

Expert Comment

by:TheMozz
ID: 34917436
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
 
LVL 10

Assisted Solution

by:John Claes
John Claes earned 100 total points
ID: 34917530
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
 
LVL 8

Accepted Solution

by:
TheMozz earned 400 total points
ID: 34917536
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This video discusses moving either the default database or any database to a new volume.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now