2

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

nixgadget
  • 6,983
  • 16
  • 70
  • 103

1 Answers1

2

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.

leppie
  • 115,091
  • 17
  • 196
  • 297
  • You can use SetMapMode according to http://www.pinvoke.net/default.aspx/gdi32/SetMapMode.html# – nixgadget Nov 01 '11 at 06:10
  • 2
    I would not trust that site for applicable usage. Try find some other sources confirming that you can indeed use it. Most of the signatures on that site is autogenerated. – leppie Nov 01 '11 at 06:17