我想将图形 x,y 坐标 x,y 转换为数学坐标
(在这张图片中,您可以看到图形 x,y 和数学 x,y 之间的差异
e事件得到的图形x和图形y
int graphicalx;
int graphicaly;
graphicalx = e.X;
graphicaly = e.Y;
他们在表单中通过两个标签显示只是应该在表单上移动鼠标
现在将图形 x,y 转换为数学 x,y 的公式是这样的:
图形 x = 数学 x + Alfa
图形 y = -数学 y + Beta
现在 Alfa 和 Beta 通过以下方式获得:
你得到你的电脑分辨率: 我的示例是:1600 * 800
阿尔法 = 1600 /2 = 800
贝塔 = 800/2 = 450
最后:阿尔法 = 800 贝塔 = 450
现在我的程序运行不好,问题出在哪里?
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
int graphicalx;
int graphicaly;
int mathematicalx;
int mathematicaly;
graphicalx = e.X;
graphicaly = e.Y;
if (graphicalx > 0)
{
graphicalx = graphicalx * -1; //if graphicalX was positive do it negative
}
if (graphicaly > 0)
{
graphicaly = graphicaly * -1; //if it graphicalY was positive do it negative
}
if (graphicalx < 0)
{
graphicalx = graphicalx * +1; // if graphicalX was negative do it positive
}
if (graphicaly < 0)
{
graphicaly = graphicaly * +1; // if graphicalY was negative do it positive
}
mathematicalx = graphicalx + 800; // the formula for obtain the mathematical x
mathematicaly = graphicaly * -1 + 450; // the formula for obtain the mathematical y
label1.Text = "X = " +mathematicalx.ToString();
label3.Text = "Y = " + mathematicaly.ToString();
}
表格 1 属性:
Windows 状态 = 最大化
FormBorderStyle = 无