主题:处理鼠标事件(获取x y坐标怎么错了啊)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace mouseevent
{
public partial class Form1 : Form
{
private bool tracking = false;
string coordinateDisplay = null;
public Form1()
{
InitializeComponent();
}
private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
tracking=true;
}
private void Form1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
tracking = false;
MouseCoordinateDisplay.Clear();
}
private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (tracking)
{
coordinateDisplay = "X: " + e.X + "Y: " + e.Y;
MouseCoordinateDisplay.Text = coordinateDisplay;
}
}
public void Main()
{
Form1 a=new Form1();
this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseDown);
this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseUp);
this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseMove);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
private void MouseCoordinateDisplay_TextChanged(object sender, EventArgs e)
{
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace mouseevent
{
public partial class Form1 : Form
{
private bool tracking = false;
string coordinateDisplay = null;
public Form1()
{
InitializeComponent();
}
private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
tracking=true;
}
private void Form1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
tracking = false;
MouseCoordinateDisplay.Clear();
}
private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (tracking)
{
coordinateDisplay = "X: " + e.X + "Y: " + e.Y;
MouseCoordinateDisplay.Text = coordinateDisplay;
}
}
public void Main()
{
Form1 a=new Form1();
this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseDown);
this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseUp);
this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseMove);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
private void MouseCoordinateDisplay_TextChanged(object sender, EventArgs e)
{
}
}
}