在picturebox中画连续线 C#
答案:2 悬赏:10 手机版
解决时间 2021-03-05 13:36
- 提问者网友:浮克旳回音
- 2021-03-04 23:20
急求代码!!!
最佳答案
- 五星知识达人网友:患得患失的劫
- 2021-03-04 23:40
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace CSharpTemp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Controls.Add(new MyControl() { Dock = DockStyle.Fill });
}
}
class Line
{
protected List points = new List();
public void Add(Point p)
{
points.Add(p);
}
public void Draw(Graphics g, Pen pen)
{
if (points.Count >= 2)
g.DrawLines(pen, points.ToArray());
}
}
class MyControl : Control
{
protected List lines = new List();
public MyControl()
{
DoubleBuffered = true;
}
protected override void OnMouseDown(MouseEventArgs e)
{
Line line = new Line();
line.Add(e.Location);
lines.Add(line);
}
protected override void OnMouseMove(MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
lines.Last().Add(e.Location);
Invalidate();
}
}
protected override void OnPaint(PaintEventArgs e)
{
foreach (Line l in lines)
l.Draw(e.Graphics, Pens.Black);
}
}
}
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace CSharpTemp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Controls.Add(new MyControl() { Dock = DockStyle.Fill });
}
}
class Line
{
protected List
public void Add(Point p)
{
points.Add(p);
}
public void Draw(Graphics g, Pen pen)
{
if (points.Count >= 2)
g.DrawLines(pen, points.ToArray());
}
}
class MyControl : Control
{
protected List
public MyControl()
{
DoubleBuffered = true;
}
protected override void OnMouseDown(MouseEventArgs e)
{
Line line = new Line();
line.Add(e.Location);
lines.Add(line);
}
protected override void OnMouseMove(MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
lines.Last().Add(e.Location);
Invalidate();
}
}
protected override void OnPaint(PaintEventArgs e)
{
foreach (Line l in lines)
l.Draw(e.Graphics, Pens.Black);
}
}
}
全部回答
- 1楼网友:往事埋风中
- 2021-03-04 23:47
清除image:
graphics g = graphics.fromimage(picturebox1.image);
g.clear(color.white);
g.dispose();
picturebox1.refresh();
清除背景:
graphics g = graphics.fromimage(picturebox1.backgroundimage);
g.clear(color.white);
g.dispose();
picturebox1.refresh();
去掉image,显示出背景
picturebox1.image = null;
picturebox1.refresh();
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯