如何获取坐标值
我想通过鼠标移动获取当前的坐标值,并显示在文本框中,但是我写的程序不能实现,请各位帮帮小弟,谢谢了。
public Point StartPt, EndPt;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
StartPt.X = e.X;
StartPt.Y = e.Y;
this.textBox1.Text = Convert.ToString(StartPt.X);
this.textBox2.Text = Convert.ToString(StartPt.Y);
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
EndPt.X = e.X;
EndPt.Y = e.Y;
this.textBox1.Text =Convert.ToString( EndPt.X);
this.textBox2.Text =Convert.ToString( EndPt.Y);
}
------解决方案--------------------C# code
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
EndPt.X = e.X;
EndPt.Y = e.Y;
this.textBox1.Text =Convert.ToString( EndPt.X);
this.textBox2.Text =Convert.ToString( EndPt.Y);
[color=#FF0000]this.textBox1.Refresh();
this.textBox2.Refresh();[/color]
}
------解决方案--------------------
首要条件,当前焦点在FORM上
------解决方案--------------------
试过了,不用那么麻烦,,
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
textBox1.Text = "X="+MousePosition.X ;
textBox1.Text = "Y="+MousePosition.Y ;
}
------解决方案--------------------
------解决方案--------------------
[code=C#][/code]
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
textBox1.Text ="("+e.X.ToString()+","+e.Y.ToString()+")";
}