有人可以幫我把下面的代碼翻譯成C#的代碼。 mapPicture是GDI代碼中的圖片對象,但是它是C#中的面板。 我已經做了如下代碼,C#相當於C++的GDI代碼
原始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);
哪部分是你陷入對具體?你問這個問題的方式,看起來你只是要求代碼審查。 –
你可以更具體一點,你有什麼問題嗎?是不是工作,什麼沒有顯示等 – TJB
我還沒有實際測試過,但我想確認的是SetMapMode和SetViewportOrg在C#中的等價物。不知道我是否做得正確! – nixgadgets