グラフィカルな x,y 座標 x,y を数学的座標に変換したい
(この図では、グラフィカルな x,y と数学的な x,y の違いがわかります
e イベントによって取得されるグラフィカル x およびグラフィカル y
int graphicalx;
int graphicaly;
graphicalx = e.X;
graphicaly = e.Y;
フォーム内の2つのラベルで示されているのは、フォーム上でマウスを動かすだけです
グラフィックx、yを数学x、yに変換する式は次のとおりです。
グラフィカルな x = 数学的 x + アルファ
グラフィカルな y = -数学的な y + ベータ
これで、アルファとベータは次のように取得されます。
あなたはあなたのコンピュータの解像度を得る: 私のサンプルの場合: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 = なし