using System.Drawing;
using System.Runtime.InteropServices;
...
[DllImport("user32.dll")]
private static extern IntPtr FindWindow(String sClassName, String sAppName);
....
IntPtr Hwnd = FindWindow("ClassName", "AppName");
Graphics g = Graphics.FromHwnd(Hwnd);
Pen myPen = new Pen(Color.Black, 4);
Point P1 = new Point(100, 400);
Point P2 = new Point(1300, 400);
g.DrawLine(myPen, P1, P2);
g.Dispose();
答案 0 :(得分:0)
您必须对屏幕进行计算,才能将世界坐标转换为屏幕坐标。屏幕上的每个像素(屏幕坐标)在世界坐标上都有一个等效的x,y,并且当您在游戏场景中移动屏幕时,此关系也会发生变化。
您想在世界坐标中以x = 100,y = 400开始绘制。如果屏幕中心位于x,y且屏幕分辨率为800x600,则代码应为:
Point P1 = new Point(400, 300);
Point P2 = new Point(1600, 300);
g.DrawLine(myPen, P1, P2);