日期:2014-05-19  浏览次数:21068 次

如何画出两条垂直的线,跟随着鼠标的移动而移动。
如何画出两条垂直的线,跟随着鼠标的移动而移动。

------解决方案--------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
public partial class Form1 : Form
{
Point OldPoint;
Pen OldPen, NewPen;
public Form1()
{
InitializeComponent();
OldPoint = new Point(0, 0);
OldPen = new Pen(this.BackColor);
NewPen = new Pen(this.ForeColor);
}

private void Form1_MouseMove(object sender, MouseEventArgs e)
{
Graphics My = this.CreateGraphics();

//旧横线
My.DrawLine(OldPen, OldPoint.X, 0, OldPoint.X, this.Size.Width);
//旧竖线
My.DrawLine(OldPen, 0, OldPoint.Y, this.Size.Width, OldPoint.Y);
//新横线
My.DrawLine(NewPen,e.X,0,e.X,this.Size.Width);
//新竖线
My.DrawLine(NewPen, 0, e.Y, this.Size.Width, e.Y);
OldPoint = e.Location;

}
}
}
很简单的实现,只有一个窗口,如果有背景图就不能这样了!
------解决方案--------------------
GDI 用异或笔话,原地重画即可擦除还原背景