我正在使用窗口应用程序和C#..我有一张在应用程序开始时看不见的图片..当点击某个按钮时,必须显示图片框..
我使用这种编码,但图片框不可见
private void save_click(object sender, EventArgs e)
{
pictureBox1.Visible = true;
pictureBox1.Show();
//does the work here
//storing and retreiving values from datadase
pictureBox1.Visible = false;
pictureBox1.Hide();
}
Run Code Online (Sandbox Code Playgroud)
PS ..在图片框中我显示了一个gif ..所以用户会知道一些工作正在后台进行..这个功能需要很长时间才能完成...
假设保存到数据库需要一些时间,您应该异步使用BackgroundWorker,一旦操作完成就隐藏PictureBox.
当前未显示图像的原因是因为在长时间运行的保存操作发生时,Windows消息未被处理,因此您的表单将无法响应用户输入而不执行重新绘制.保存操作完成后,消息开始再次处理,图片框已再次隐藏.
小智 5
为了避免使用多线程,你所能做的就是pictureBox1.Refresh();如下pictureBox1.Visible = true;:
private void save_click(object sender, EventArgs e)
{
pictureBox1.Visible = true;
pictureBox1.Refresh();
//does the work here
//storing and retreiving values from datadase
pictureBox1.Visible = false;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12135 次 |
| 最近记录: |