我的程序计算出一堆东西,将其显示在TextBox中,然后继续。我想对我的程序进行截屏,以确保它做出正确的计算和决策。但是,我的TextBox文本似乎总是落后。我该如何解决?
textBox26.Text = "HELLO";
String input = File.ReadAllText(@"C:\XXXXXXXXXXXXXX\LOG.txt");
int imageid = Convert.ToInt32(input) + 1;
Bitmap bmp = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
using (Graphics g = Graphics.FromImage(bmp))
{
g.CopyFromScreen(0, 0, 0, 0, Screen.PrimaryScreen.Bounds.Size);
bmp.Save(@"C:\XXXXXXXXXXXXXX\" + imageid.ToString("D5") + ".png"); // saves the image
}
File.WriteAllText(@"C:\XXXXXXXXXXXXXX\LOG.txt", "" + imageid);
我的屏幕快照显示空白的TextBox。请帮忙
It lags behind because the thread that will redraw the textbox is busy running your application code and your code goes straight from setting the text to taking the screenshot without giving the thread chance to leave your code and redraw the box. The redraw will only happen when your code is done executing. The rough and ready way to achieve what you want would be to call
Application.DoEvents()
between setting the text and taking the shot.I believe after you set the textbox's text property, I would call
Application.DoEvents()
to flush the messages out.