Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Refresh Winforms control c#

Posted on 2011-02-17
3
Medium Priority
?
2,809 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:Charles Baldo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 400 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 1600 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

636 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