简体   繁体   English

如何重绘或刷新屏幕

[英]How to Redraw or Refresh a screen

I am working on a wpf application. 我正在研究一个wpf应用程序。 Here I need to use System.Windows.Forms.FolderBrowserDialog in my Wpf application. 在这里,我需要在我的Wpf应用程序中使用System.Windows.Forms.FolderBrowserDialog。

        System.Windows.Forms.FolderBrowserDialog openFolderBrowser = new System.Windows.Forms.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). 我启动一个FolderBrowserDialog,选择一个文件夹,然后单击确定,然后我启动另一个System.Windows.Forms.FolderBrowserDialog,我的问题是当我选择一个文件夹并在此FolderBrowserDialog中单击确定时,FolderBrowserDialog的阴影仍然在屏幕上(均值我的屏幕没有刷新)。 I need to minimize or resize it in order to remove the shadow of FolderBrowserDialog. 我需要最小化或调整大小以删除FolderBrowserDialog的阴影。 How can I solve this issue? 我该如何解决这个问题? Any help plz? 任何帮助PLZ?

Edit: 编辑:

I found the solution. 我找到了解决方案。 I called OnRender method on my wpf Window and it worked for me. 我在我的wpf Window上调用了OnRender方法,它对我有用。 It redraws everythign on the screen. 它会重新绘制屏幕上的每一个标记。

您可以调用InvalidateVisual方法来刷新UI。

on a form code 在表单代码上

 Update();

refreshes screen and updates ui. 刷新屏幕并更新ui。

We are using winforms so Update() is a basic function that redraws the window content. 我们使用的是winforms,因此Update()是一个重绘窗口内容的基本功能。 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. 否则label1.text永远不会改变。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM