展开全部
public partial class MainForm : Form
{
Graphics g;
Timer timer;
Point pos, pos2;
bool isMouseUp = true;
int interval;
public MainForm()
{
InitializeComponent();
}
void MainFormLoad(object sender, EventArgs e)
{
this.Width = 800;
this.Height = 600;
timer = new Timer();
timer.Interval = 2;
timer.Tick += new EventHandler(timer_Tick);
timer.Enabled = true;
g = this.CreateGraphics();
}
void timer_Tick(object sender, EventArgs e)
{
pos = PointToClient(MousePosition);
if(!isMouseUp)
{
interval++;
if(interval > 1)
{
g.DrawLine(new Pen(Color.Red), pos.X, pos.Y, pos2.X, pos2.Y);
pos2 = pos;
interval = 0;
}
}
}
void MainFormMouseDown(object sender, MouseEventArgs e)
{
pos2 = pos;
isMouseUp = false;
}
void MainFormMouseUp(object sender, MouseEventArgs e)
{
isMouseUp = true;
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询