using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text;
using System.Windows.Forms;
namespace test_RJJH1 {
public partial class Form1 : Form {
public Form1() {
InitializeComponent(); }
int startX; int startY; Graphics g;
bool isDragging = false; Point startP; Point lastP;
private void Form1_MouseDown(object sender, MouseEventArgs e) {
startX = e.X; startY = e.Y;
isDragging = true; startP.X = e.X; startP.Y = e.Y; lastP.X = -1; lastP.Y = -1;
this.Capture = true;
}
private void Form1_Load(object sender, EventArgs e) {
this.StartPosition = FormStartPosition.CenterScreen; this.BackColor = Color.Snow; startP = new Point(); lastP = new Point();
}
private void Form1_MouseUp(object sender, MouseEventArgs e) {
g = this.CreateGraphics();
Pen p = new Pen(Color.Red, 4);
g.DrawLine(p, startX, startY, e.X, e.Y); isDragging = false ; }
private void Form1_MouseMove(object sender, MouseEventArgs e) {
if (isDragging) {
Point p1; Point p2;
if (lastP.X != -1) {
p1 = PointToScreen(startP); p2 = PointToScreen(lastP);
ControlPaint.DrawReversibleLine(p1, p2, Color.Red); }
lastP.X = e.X; lastP.Y = e.Y;
p1 = PointToScreen(startP); p2 = PointToScreen(lastP);
}
} } }
ControlPaint.DrawReversibleLine(p1, p2, Color.Red);
因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- huatuo8.com 版权所有 湘ICP备2023022238号-1
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务