0

首先,感谢大家多年来的帮助。我在这个网站上找到了很多解决方案,但这个似乎是独一无二的。

我所拥有的是在后台工作人员中创建的带有图片框的表单(因为如果后台工作人员在显示期间我需要 UI 做出响应)。该图片框正在使用后台工作程序中运行的 while 循环进行更新。

后台工作人员被称为:

private void Play_Click(object sender, EventArgs e)
{
    OpenFileDialog openFile = new OpenFileDialog();
    openFile.ShowDialog();

    FileName = openFile.FileName;

    this.backgroundWorker1.RunWorkerAsync();
}

private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
        VisualPlayer.Player player = new VisualPlayer.Player(FileName);
}

这是在 backgroundWorker 中调用的函数的示例

public void VideoPlayer(string fileName)
{

    PlayerScreen.VideoWindow videoWindow = new PlayerScreen.VideoWindow();
    videoWindow.Show();
    videoWindow.TopMost = true;
    PictureBox pictureBox = (PictureBox)videoWindow.Controls[0];

    var startTime = DateTime.Now;
    var millisecondsRemaining = GetFileLength(fileName);
    var endTime = startTime.AddMilliseconds(millisecondsRemaining);

    while (millisecondsRemaining > 0)
    {
        millisecondsRemaining = Convert.ToInt32(endTime.Subtract(DateTime.Now).TotalMilliseconds);
        ... do the pictureBox updates here ...
    }

}

所以一切正常,一切都很好,但一方面,我无法选择 videoWindow。我需要能够选择它、移动它、双击它来调整它的大小等,但是当我将鼠标移到它上面时,我所拥有的只是沙漏。

现在我的解决方案是在 While 循环中添加可怕的 Application.DoEvents() 来捕获鼠标事件,但这里的每个人都建议我不要使用它。

所以我想知道,是否有另一种方法来处理其他无响应的后台工作窗体上的鼠标事件?

4

0 回答 0