How to Redraw or Refresh a screen
I am working on a wpf application. Here I need to use System.Windows.Forms.FolderBrowserDialog in my Wpf application.
System.Windows.Forms.FolderBrowserDialog openFolderBrowser = new System.Windows.F开发者_JS百科orms.FolderBrowserDialog();
openFolderBrowser.Description = "Select Resource Path:";
openFolderBrowser.RootFolder = Environment.SpecialFolder.MyComputer;
if (openFolderBrowser.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
//some logic
openFolderBrowser.Dispose();
}
I launch a FolderBrowserDialog, select a Folder and click OK, and then I launch another System.Windows.Forms.FolderBrowserDialog, My problem is when I select a Folder and click OK in this FolderBrowserDialog, the shadow of FolderBrowserDialog remains on the screen(means my screen doesn't refresh). I need to minimize or resize it in order to remove the shadow of FolderBrowserDialog. How can I solve this issue? Any help plz?
Edit:
I found the solution. I called OnRender method on my wpf Window and it worked for me. It redraws everythign on the screen.
You can call InvalidateVisual method to refresh UI.
on a form code
Update();
refreshes screen and updates ui.
We are using winforms so Update() is a basic function that redraws the window content. so you may use it directly from a form. The basic usage could be a timer which updates a label on a screen. when timer ticks you update the label:
System.Windows.Forms.Timer t = new System.Windows.Forms.Timer();
t.Interval = 1000; // specify interval time as you want
t.Tick += new EventHandler(timer_Tick);
t.Start();
void timer_Tick(object sender, EventArgs e)
{
label1.text = DateTime.Now.ToString("h:mm:ss"));
Update(); //this will refresh the form and label's text is updated.
}
otherwise label1.text will never change.
精彩评论