我似乎在用 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);
提前致谢
最佳答案
最接近的是在 Graphics
对象上设置 PageUnit
。据我所知,没有等价于 MM_LOMETRIC
的东西,但是有 Millimeter
。
您可能可以将其与 ScaleTransform
结合使用以获得所需的效果。
关于C# GDI+ 设置 map 模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7962205/