c#仿windows画图程序完整版
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
注意:本程序采用vs2008版,不兼容vs2005。
如果觉得可以就收藏吧。本程序仅供做c#实验的同学的一个参考。画图程序设计
实验目的:
1.了解.net下多媒体编程技术。
2.掌握Graphics类绘制图像的方法。
3.掌握使用GDI+技术显示和保存图像的方法。
实验要求:
1.设计一个画图程序。
2.可以绘制各种图形,可以选择画笔的线型和颜色。
3.可以将绘制的图像保存为位图文件。
Form1.cs
//主程序代码
using System;
using System.Collections.Generic;
using ponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.Collections;
using ;
using .Sockets;
using System.Threading;
namespace WindowsApplication1
{
public enum LineStyle { SOLID, DASH, DOT};
public partial class FrmDraw : Form
{
private Color PenColor;
private enum Shape { LINE, ELLIPSE, RECTANGLE, CIRCLE, FillRectangle, Pencil, Eraser, ELLIPSE1 };
private Shape DrawShape;
private Point StartPoint;
private Point EndPoint;
private Point z;
public Graphics gps;
private bool MouseDownFlag;
private Pen PenLine;
private SolidBrush Solid;
private Hashtable DrawObject;
private int count;
private string ShapeName;
private LineStyle lineStyle;
private bool isOpen;
private string imagePath;
private string strShape;
private string strLineStyle;
PaintEventArgs e1 = null;
int i = 0;
int j = 0;
int x2 = -1, y2 = -1;
public FrmDraw()
{
isOpen = false;
count = 0;
lineStyle = LineStyle.SOLID;
MouseDownFlag = false;
PenLine = new Pen(PenColor);
PenColor = System.Drawing.Color.Black;
DrawShape = Shape.LINE;
DrawObject = new Hashtable();
ShapeName = "LINE";
strShape = "直线";
strLineStyle = "实线";
InitializeComponent();
}
//自定义颜色
private void CoustumColor_Click(object sender, EventArgs e) {
if (colorDialog.ShowDialog() == DialogResult.OK)
{
PenColor = colorDialog.Color;
}
}
//鼠标事件
private void FrmDraw_MouseDown(object sender, MouseEventArgs e)
{
MouseDownFlag = true;
StartPoint.X = e.X;
StartPoint.Y = e.Y;
z.X = e.X;
z.Y = e.Y;
//Color clr = GetBkColor(new Point(e.X, e.Y));
// MessageBox.Show("R" + clr.R.ToString() + "G" + clr.G.ToString() + "B" + clr.B.ToString());
}
private void FrmDraw_MouseMove(object sender, MouseEventArgs e)
{
if (MouseDownFlag)
{
Color BkColor = this.BackColor;//Color.FromArgb(212, 208, 200);
if(DrawObject != null)
{
foreach (DictionaryEntry de in DrawObject)
{
string[] splipstr = de.Key.ToString().Split('|');
switch (splipstr[0])
{
case"Pencil":
((Pencil)de.Value).Draw(gps);
break;
case"LINE":
((DrawLine)de.Value).Draw(gps);
break;
case"ELLIPSE":
((DrawEelipse)de.Value).Draw(gps);
break;
case"RECTANGLE":
((DrawRectangle)de.Value).Draw(gps);
break;
case"CIRCLE":
((CIRCLE)de.Value).Draw(gps);