用picturebox的mousemove事件,畫直線時會隨著滑鼠移影片無數條直線。用Clear的話,之前畫的全會清楚。怎么養才能實作像windows畫板那樣畫直線啊???
這個困擾我好多天了,分數不多全奉上
uj5u.com熱心網友回復:
完整的代碼:https://download.csdn.net/download/caozhy/12082528問題解決的話,請結貼給分
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace T395559890
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.DoubleBuffered = true;
}
private List<Tuple<Point, Point>> lines = new List<Tuple<Point, Point>>();
private Point? pre;
private void Form1_Paint(object sender, PaintEventArgs e)
{
foreach (var item in lines)
{
e.Graphics.DrawLine(Pens.Black, item.Item1, item.Item2);
}
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
if (pre.HasValue)
{
lines.Add(new Tuple<Point, Point>(pre.Value, new Point(e.X, e.Y)));
Refresh();
}
pre = new Point(e.X, e.Y);
}
else
{
if (pre.HasValue)
{
lines.Add(new Tuple<Point, Point>(pre.Value, new Point(e.X, e.Y)));
Refresh();
}
pre = null;
}
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/80493.html
標籤:C#
