110,533
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
panel1.MouseMove += new MouseEventHandler(panel1_MouseMove);
}
Point lastPoint = new Point(-1, -1);
void panel1_MouseMove(object sender, MouseEventArgs e)
{
if( lastPoint.X >= 0 )DrawReversibleLine( lastPoint );
lastPoint = e.Location;
DrawReversibleLine( lastPoint );
}
void DrawReversibleLine(Point p)
{
ControlPaint.DrawReversibleLine(
panel1.PointToScreen(new Point(0, p.Y)),
panel1.PointToScreen(new Point(panel1.Width, p.Y)),
SystemColors.Control);
ControlPaint.DrawReversibleLine(
panel1.PointToScreen(new Point(p.X, 0)),
panel1.PointToScreen(new Point(p.X, panel1.Height)),
Color.ForestGreen);
}
}
}