我似乎在用 C# 实现 SetMapMode 时遇到了一些问题。不是 C# 方面的专家,所以我看到错误并不太惊讶。即使认为编译很好 DrawLine 也会抛出 InvalidOperationException。有任何想法吗 ?
[DllImport("gdi32.dll")]
static extern int SetMapMode(IntPtr hdc, int fnMapMode);
myPen = new Pen(Color.Black, 1);
formGraphics = envMap.CreateGraphics();
IntPtr hdc = formGraphics.GetHdc();
SetMapMode(hdc, 3); // MM_LOMETRIC
formGraphics.DrawLine(myPen, (2 * rect.Right - 60) - 15, 8, (2 * rect.Right - 60), 0);
formGraphics.DrawLine(myPen, (2 * rect.Right - 60), 0, (2 * rect.Right - 60) - 15, -8);
提前致谢