求高手帮忙使用c#_GDI+编写简易绘图板
求高手编写简易绘图板,要求可以使用鼠标点击和拖动绘制直线,折线等基本图形就可以了。我需要的是那种可以实时显示的,就是鼠标移动就可以看到绘画的线条那种,和windows自带...
求高手编写简易绘图板,要求可以使用鼠标点击和拖动绘制直线,折线等基本图形就可以了。
我需要的是那种可以实时显示的,就是鼠标移动就可以看到绘画的线条那种,和windows自带的那种画图工具那样的效果,一楼的回答只能在鼠标抬起后才能看到线条,不是我需要的效果。 展开
我需要的是那种可以实时显示的,就是鼠标移动就可以看到绘画的线条那种,和windows自带的那种画图工具那样的效果,一楼的回答只能在鼠标抬起后才能看到线条,不是我需要的效果。 展开
展开全部
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 画图板制作
{
public partial class Form1 : Form
{
Point p1 = new Point();
Point p2 = new Point();
Graphics g;
Color c = Color.Black;
int linestyle = 1;
enum style
{ line, rect, ellipse }
style mystyle = style.line;
public Form1()
{
InitializeComponent();
}
private void splitContainer1_Panel2_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
p1.X = e.X;
p1.Y = e.Y;
}
}
private void splitContainer1_Panel2_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
p2.X = e.X;
p2.Y = e.Y;
g = splitContainer1.Panel2.CreateGraphics();
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
switch (mystyle)
{
case style.line:
g.DrawLine(new Pen(c, linestyle), p1, p2);
g.Dispose();
break;
case style.rect:
g.DrawRectangle(new Pen(c, linestyle), new Rectangle(p1, new Size(Math.Abs(p2.X - p1.X), Math.Abs(p2.Y - p1.Y))));
g.Dispose();
break;
case style.ellipse:
g.DrawEllipse(new Pen(c, linestyle), new Rectangle(p1, new Size(Math.Abs(p2.X - p1.X), Math.Abs(p2.Y - p1.Y))));
g.Dispose();
break;
default:
break;
}
}
}
private void button1_Click(object sender, EventArgs e)
{
mystyle = style.line;
}
private void button2_Click(object sender, EventArgs e)
{
mystyle = style.rect;
}
private void button3_Click(object sender, EventArgs e)
{
mystyle = style.ellipse;
}
private void toolStripMenuItem1_Click(object sender, EventArgs e)
{
c = Color.Red;
}
private void 黄色ToolStripMenuItem_Click(object sender, EventArgs e)
{
c = Color.Yellow;
}
private void 蓝色ToolStripMenuItem_Click(object sender, EventArgs e)
{
c = Color.Blue;
}
private void 黑色ToolStripMenuItem_Click(object sender, EventArgs e)
{
c = Color.Black;
}
private void 自定义颜色ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (colorDialog1.ShowDialog() == DialogResult.OK)
{
c = colorDialog1.Color;
}
this.Refresh();
}
private void 号线宽ToolStripMenuItem_Click(object sender, EventArgs e)
{
linestyle = 1;
}
private void 号线宽ToolStripMenuItem1_Click(object sender, EventArgs e)
{
linestyle = 2;
}
private void 号线宽ToolStripMenuItem2_Click(object sender, EventArgs e)
{
linestyle = 3;
}
private void 号线宽ToolStripMenuItem3_Click(object sender, EventArgs e)
{
linestyle = 4;
}
private void 号线宽ToolStripMenuItem4_Click(object sender, EventArgs e)
{
linestyle = 5;
}
private void button5_Click(object sender, EventArgs e)
{
openFileDialog1.Title = "选择图片";
openFileDialog1.Filter = "Text documents(*.txt)|*.txt|All File|*.*|Jpeg文件|*.jpg";
openFileDialog1.Multiselect = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
string filname = openFileDialog1.FileName;
Bitmap map = new Bitmap(openFileDialog1.FileName);
g = splitContainer1.Panel2.CreateGraphics();
g.DrawImage(map,100,100);
}
}
}
}
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 画图板制作
{
public partial class Form1 : Form
{
Point p1 = new Point();
Point p2 = new Point();
Graphics g;
Color c = Color.Black;
int linestyle = 1;
enum style
{ line, rect, ellipse }
style mystyle = style.line;
public Form1()
{
InitializeComponent();
}
private void splitContainer1_Panel2_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
p1.X = e.X;
p1.Y = e.Y;
}
}
private void splitContainer1_Panel2_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
p2.X = e.X;
p2.Y = e.Y;
g = splitContainer1.Panel2.CreateGraphics();
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
switch (mystyle)
{
case style.line:
g.DrawLine(new Pen(c, linestyle), p1, p2);
g.Dispose();
break;
case style.rect:
g.DrawRectangle(new Pen(c, linestyle), new Rectangle(p1, new Size(Math.Abs(p2.X - p1.X), Math.Abs(p2.Y - p1.Y))));
g.Dispose();
break;
case style.ellipse:
g.DrawEllipse(new Pen(c, linestyle), new Rectangle(p1, new Size(Math.Abs(p2.X - p1.X), Math.Abs(p2.Y - p1.Y))));
g.Dispose();
break;
default:
break;
}
}
}
private void button1_Click(object sender, EventArgs e)
{
mystyle = style.line;
}
private void button2_Click(object sender, EventArgs e)
{
mystyle = style.rect;
}
private void button3_Click(object sender, EventArgs e)
{
mystyle = style.ellipse;
}
private void toolStripMenuItem1_Click(object sender, EventArgs e)
{
c = Color.Red;
}
private void 黄色ToolStripMenuItem_Click(object sender, EventArgs e)
{
c = Color.Yellow;
}
private void 蓝色ToolStripMenuItem_Click(object sender, EventArgs e)
{
c = Color.Blue;
}
private void 黑色ToolStripMenuItem_Click(object sender, EventArgs e)
{
c = Color.Black;
}
private void 自定义颜色ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (colorDialog1.ShowDialog() == DialogResult.OK)
{
c = colorDialog1.Color;
}
this.Refresh();
}
private void 号线宽ToolStripMenuItem_Click(object sender, EventArgs e)
{
linestyle = 1;
}
private void 号线宽ToolStripMenuItem1_Click(object sender, EventArgs e)
{
linestyle = 2;
}
private void 号线宽ToolStripMenuItem2_Click(object sender, EventArgs e)
{
linestyle = 3;
}
private void 号线宽ToolStripMenuItem3_Click(object sender, EventArgs e)
{
linestyle = 4;
}
private void 号线宽ToolStripMenuItem4_Click(object sender, EventArgs e)
{
linestyle = 5;
}
private void button5_Click(object sender, EventArgs e)
{
openFileDialog1.Title = "选择图片";
openFileDialog1.Filter = "Text documents(*.txt)|*.txt|All File|*.*|Jpeg文件|*.jpg";
openFileDialog1.Multiselect = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
string filname = openFileDialog1.FileName;
Bitmap map = new Bitmap(openFileDialog1.FileName);
g = splitContainer1.Panel2.CreateGraphics();
g.DrawImage(map,100,100);
}
}
}
}
东莞大凡
2024-11-19 广告
2024-11-19 广告
作为东莞市大凡光学科技有限公司的工作人员,对于halcon标定板有所了解。Halcon标定板是高精度相机标定的关键工具,通常采用实心圆点或方格作为标志点。我们公司提供的halcon标定板,具有高精度、稳定可靠的特点,适用于机器视觉领域的各种...
点击进入详情页
本回答由东莞大凡提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询