C# GDI+设置地图模式
我似乎在 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);
提前致谢
I seem to be having some problems with implementing SetMapMode in C#. Not an expert in C# so Im not too surprised that im seeing errors. Even thought the compilation is fine DrawLine throws InvalidOperationException. Any ideas ?
[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);
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最接近的是在
Graphics
对象上设置PageUnit
。据我所知,没有与MM_LOMETRIC
等效的东西,但有Millimeter
。您可以将其与 ScaleTransform 结合起来以获得所需的效果。
The closest thing to that is setting the
PageUnit
on theGraphics
object. From what I can see there is no equivalent toMM_LOMETRIC
, but there isMillimeter
.You could probably combine that with
ScaleTransform
to get the desired effect.