【发布时间】:2015-11-17 14:20:59
【问题描述】:
我有一个带有停靠面板的 WinForm。 我覆盖了 Panel 的 Paint 事件。 我有一行设置 _graphics 对象:
private Graphics _graphics;
在覆盖中我初始化 _graphics 对象:
private void GridPanel_Paint(object sender, PaintEventArgs e)
{
_graphics = e.Graphics;
<snip>
…
</snip>
}
愚蠢的部分来了,我可以在像 MouseMove 这样的任何其他事件中使用这个 _graphics 对象吗?
【问题讨论】:
-
你可以(并且为了短代码部分应该)将
e.Graphics对象从Paint事件传递给助手职能。不要不要尝试缓存它(也不要使用CreateGraphics),否则会发生可怕的事情! - 所以答案是 NO 你不应该那样做!