怎么获取坐标值

发布时间2018/9/22 3:59:06

下载次数 0 次 访问量157 次

免开发-应用中心上线啦,专注提供优质插件源码和产品应用!

如何获取坐标值
我想通过鼠标移动获取当前的坐标值,并显示在文本框中,但是我写的程序不能实现,请各位帮帮小弟,谢谢了。
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 ;
}
------解决方案--------------------
探讨
当前焦点在Form上是什么意思啊,大侠能说的清楚点不,谢谢了。

------解决方案--------------------
[code=C#][/code]
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
textBox1.Text ="("+e.X.ToString()+","+e.Y.ToString()+")"; 
}

网友评论

发表评论

欢迎评论哦!