我有 ac# windows 窗體程序,用戶可以在其中用鼠標在圖片框中的圖像上畫線。圖形是由 pictureBox1_Paint 方法創建的。如何擦除繪制的線條并保持圖像完整?在這里定義的默認圖像:public lineTest(){ InitializeComponent(); defaultImage = pictureBox1.Image; } 畫出這樣的線條: private void pictureBox1_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) lines.Push(new Line { Start = e.Location }); } private void pictureBox1_MouseMove(object sender, MouseEventArgs e) { if (lines.Count > 0 && e.Button == System.Windows.Forms.MouseButtons.Left) { lines.Peek().End = e.Location; pictureBox1.Invalidate(); } }private void pictureBox1_Paint(object sender, PaintEventArgs e) { foreach (var line in lines) { Pen magenta = new Pen(Color.Magenta, 5); e.Graphics.DrawLine(magenta, line.Start, line.End); } }并嘗試使用以下方法擦除線條:private void button1_Click(object sender, EventArgs e) { pictureBox1.Image = defaultImage; pictureBox1.Invalidate(); }似乎什么也沒發生。
在c# windows窗體中清除畫在圖片框上的線條
慕田峪7331174
2022-01-09 16:22:21