有人可以帮我将以下内容翻译成 C# 等价物。mapPicture 是 GDI 代码中的图片对象,但它是 C# 中的面板。我已经完成了如下代码,
原始 MFC 代码,
CDC *dc = mapPicture.GetDC();
CRect maprect;
mapPicture.GetClientRect(&maprect);
CPen pen,*oldpen;
dc->Rectangle(&rect);
pen.CreatePen(PS_SOLID,1,RGB(0,0,0));
oldpen=dc->SelectObject(&pen);
dc->SetMapMode(MM_LOMETRIC);
CPoint b1=dc->SetViewportOrg(25,rect.Height()-25);
dc->SetTextColor(RGB(0,0,0));
dc->MoveTo(0,0);
dc->LineTo((2*rect.right - 60),0);
dc->MoveTo(0,0);
dc->LineTo(0,2*rect.bottom);
dc->MoveTo((2*rect.right - 60)-15,8);
dc->LineTo((2*rect.right - 60),0);
dc->LineTo((2*rect.right - 60)-15,-8);
dc->SetTextAlign(TA_RIGHT|TA_BOTTOM);
dc->TextOut((2*rect.right - 55),-55,"X");
到目前为止我已经完成的 C# 代码,
myPen = new Pen(Color.Black, 1);
formGraphics = mapPicture.CreateGraphics();
Rectangle rect = mapPicture.ClientRectangle;
formGraphics.PageUnit = GraphicsUnit.Millimeter;
formGraphics.TranslateTransform(25, rect.Height - 25);
formGraphics.DrawLine(myPen, 0, 0, (2 * rect.Right - 60), 0);
formGraphics.DrawLine(myPen, 0, 0, 0, 2 * rect.Bottom);
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);
SolidBrush drawBrush = new SolidBrush(Color.Black);
Font drawFont = new Font("Microsoft Sans Serif", 9);
formGraphics.DrawString("X", drawFont, drawBrush, (2 * rect.Right - 55), -55);