C# GDI+设置地图模式

发布于 2024-12-12 20:44:19 字数 561 浏览 10 评论 0原文

我似乎在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浪漫之都 2024-12-19 20:44:19

最接近的是在 Graphics 对象上设置 PageUnit。据我所知,没有与 MM_LOMETRIC 等效的东西,但有 Millimeter

您可以将其与 ScaleTransform 结合起来以获得所需的效果。

The closest thing to that is setting the PageUnit on the Graphics object. From what I can see there is no equivalent to MM_LOMETRIC, but there is Millimeter.

You could probably combine that with ScaleTransform to get the desired effect.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文