关于c#画线

open422000 open422000 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

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;
using System.Drawing.Drawing2D;

namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
private PointF current;
private PointF movepf;

public Form1()
{
InitializeComponent();
}


private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
{

current = e.Location;

}

private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
movepf = e.Location;
Invalidate();
}

protected override void OnPaint(PaintEventArgs e)
{

Bitmap mp = new Bitmap(pictureBox1.Width, pictureBox1.Height);

Pen pen = new Pen(Color.Blue);

SolidBrush drawBrush = new SolidBrush(Color.Black);
using (Graphics g = Graphics.FromImage(mp))
{

g.DrawImage(mp, pictureBox1.ClientRectangle.X, pictureBox1.ClientRectangle.Y);
g.DrawLine(pen, current, movepf);

PointF pt1 = new PointF();

pt1.X = (current.X + movepf.X) / 2;
pt1.Y = (current.Y + movepf.Y) / 2;


g.DrawString("12345", this.Font, drawBrush, pt1);

using (Graphics gg = this.CreateGraphics())
{
gg.DrawImage(mp, pictureBox1.ClientRectangle.X, pictureBox1.ClientRectangle.Y);

}
}
base.OnPaint(e);
}


}
}





[img=C:\Users\Administrator\Desktop\1.png]
[/img]


就是想知道 我这样画线, 就一个窗体一个picturebox ,我想在picturebox里面画线,可是线条老出在form上面 怎么办呢
...全文
评论 2
收藏 已收藏
分享
返回顶部
open422000
组件/控件开发 8,830 成员 7,151 内容