0

我有以下问题。我正在使用本机 GDI+ 在 Windows 窗体的面板表面上绘图(绘图算法在本机 DLL 内,由 P/Invoke 调用)。一切都很好,但直到一个人改变面板的大小。如果它被缩小,它被正确渲染。但是,如果它被放大,只有面板区域中与其原始大小相对应的部分会被 GDI+ 重绘。

为什么会这样?当面板调整大小时,我真的必须每次都创建新的 Graphics 对象吗?

4

2 回答 2

2

Hans Passant 在评论中回答:

You found out why, the Graphics object no longer matches the state of the window. You are assuming that it is expensive to create. It isn't, it only costs couple of dozen microseconds. It is only expensive to keep it around, needlessly using memory. Anyhoo, you need to recreate it when the window state changes.

于 2013-01-08T21:19:42.453 回答
0

假设您正在面板的绘画事件中进行绘图...如果不是这种情况,请告诉我。

调整大小时尝试在面板上调用 .Invalidate。

于 2011-10-23T14:53:16.583 回答