将PictureBox的图像设置为同一图像会强制重绘吗?

时间:2015-07-13 17:55:32

标签: c# image winforms paint repaint

我有一个后台线程,用于检查硬件设备(相机)的通信状态,并使用绿色圆圈或红色X相应地更新表单上的图像。

public bool cameraStatus;

public MainForm()
{
   InitializeComponent();

   // add the UpdateDisplay function to a dictionary that will be periodically called
   updateMethods.Add(new EventHandler(UpdateDisplay));
}

public void UpdateDisplay()
{
   if (cameraStatus)
      imgCameraStatus.Image = Properties.Resources.camera_good;
   else
      imgCameraStatus.Image = Properties.Resources.camera_bad;
}

UpdateDisplay函数经常被调用,大约50毫秒左右。大部分时间cameraStatus不会更改,因此imgCameraStatus.Image会保持设置为相同的值。

图像没有闪烁,我想知道图像是否实际上每次都被窗口重绘,因为源不会改变。我不确定如何在WinForms绘制周期中进入较低级别的绘制函数调用。

1 个答案:

答案 0 :(得分:1)

查看the source code,设置Image属性会调用名为InstallNewImage的私有方法。此方法将始终调用Invalidate,它将安排重新绘制消息队列中的PictureBox

相关问题