【发布时间】:2016-05-29 08:52:54
【问题描述】:
我有一个 SplitContainer(确切地说是一个 NonFlickerSplitContainer),我将它的两个面板都视为一个单独的画布来进行绘画。我使用 Graphics.DrawImage 方法分别在面板上绘制位图。我先刷新 Panel1,然后刷新 Panel2,这会导致垂直/水平撕裂 - Panel1 的绘画结束,然后 Panel2 的绘画开始 - 这就是原因。我的问题的解决方案是什么?我使用 splitContainer 作为具有前后功能的“位图视频流”的输出。也许我可以以某种方式冻结 UI,直到 Panel2_Paint 结束?
private void splitContainer_Panel1_Paint(object sender, PaintEventArgs e)
{
if (frameA != null)
{
if (ORIGINAL_SIZE_SET)
e.Graphics.DrawImage(frameA, 0, 0);
else
e.Graphics.DrawImage(frameA, 0, 0, ClientSize.Width, ClientSize.Height);
}
}
private void splitContainer_Panel2_Paint(object sender, PaintEventArgs e)
{
if (frameB != null)
{
//...
if (ORIGINAL_SIZE_SET)
e.Graphics.DrawImage(frameB, x, y);
else
e.Graphics.DrawImage(frameB, x, y, ClientSize.Width, ClientSize.Height);
}
}
private Bitmap frameA = null;
private Bitmap frameB = null;
private void RefreshOutput(bool refreshClipA = true, bool refreshClipB = true)
{
if (refreshClipA)
{
frameA = GetVideoFrame(...);
//...
}
if (refreshClipB)
{
frameB = GetVideoFrame(...);
//...
}
if (refreshClipA)
splitContainer.Panel1.Refresh();
if (refreshClipB)
splitContainer.Panel2.Refresh();
}
【问题讨论】:
-
我希望有一种方法可以冻结拆分容器,直到我说它可以再次恢复。不过,我认为没有这样的方法。这样做的肮脏方法可能是在 Panel1 单元上用前一个位图覆盖一个图片框, Panel2_Paint 结束,对吧?考虑一下是不是太肮脏和效率低下?
-
您可能无法强制两个面板同时绘制。我现在正在使用单个面板进行绘画。我将部分位图绘制在面板上。我将 Mouse_Click 视为先前的 Splitter_Moved 事件。这是一个更有效的解决方案。如果您遇到与我相同的问题,请首先放弃 SplitContainer。我没有写它,但在我问这个问题之前我已经找到了一种同时绘画的方法——尽管不要使用它,因为它绝对是一种非常肮脏和故障的方法。我在 Panel1 和 Panel2 上停靠了两个 PictureBox,并使用了它的 Image 属性。
标签: c# winforms bitmap paint splitcontainer