欢迎来到装配图网! | 帮助中心 装配图网zhuangpeitu.com!
装配图网
ImageVerifierCode 换一换
首页 装配图网 > 资源分类 > DOC文档下载
 

C#经典实例----画图程序

  • 资源ID:139743275       资源大小:190KB        全文页数:30页
  • 资源格式: DOC        下载积分:20积分
快捷下载 游客一键下载
会员登录下载
微信登录下载
三方登录下载: 微信开放平台登录 支付宝登录   QQ登录   微博登录  
二维码
微信扫一扫登录
下载资源需要20积分
邮箱/手机:
温馨提示:
用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)
支付方式: 支付宝    微信支付   
验证码:   换一换

 
账号:
密码:
验证码:   换一换
  忘记密码?
    
友情提示
2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

C#经典实例----画图程序

这是一种简朴旳画图程序其源码是:using System.Drawing;using System;using System.Windows.Forms;using System.Drawing.Imaging;namespace WindowsApplication1 partial class Form1 / <summary> / 必需旳设计器变量。 / </summary> private System.ComponentModel.IContainer components = null; / <summary> / 清理所有正在使用旳资源。 / </summary> / <param name="disposing">假如应释放托管资源,为 true;否则为 false。</param> protected override void Dispose(bool disposing) if (disposing && (components != null) components.Dispose(); base.Dispose(disposing); public Form1() InitializeComponent(); #region Windows 窗体设计器生成旳代码 / <summary> / 设计器支持所需旳措施 - 不要 / 使用代码编辑器修改此措施旳内容。 / </summary> private void InitializeComponent() ponents = new System.ComponentModel.Container(); this.menuStrip1 = new System.Windows.Forms.MenuStrip(); this.文献ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.Open = new System.Windows.Forms.ToolStripMenuItem(); this.NEW = new System.Windows.Forms.ToolStripMenuItem(); this.saveFile = new System.Windows.Forms.ToolStripMenuItem(); this.Exist = new System.Windows.Forms.ToolStripMenuItem(); this.编辑颜色ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.有关ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.toolTip1 = new System.Windows.Forms.ToolTip(ponents); this.menuStrip2 = new System.Windows.Forms.MenuStrip(); this.画笔工具ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.画直线ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.画椭圆ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.画矩形ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.橡皮擦ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.鼠标ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.saveFiles = new System.Windows.Forms.SaveFileDialog(); this.openFiles = new System.Windows.Forms.OpenFileDialog(); this.panel1 = new System.Windows.Forms.Panel(); this.label1 = new System.Windows.Forms.Label(); this.button1 = new System.Windows.Forms.Button(); this.menuStrip1.SuspendLayout(); this.menuStrip2.SuspendLayout(); this.panel1.SuspendLayout(); this.SuspendLayout(); / / menuStrip1 / this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem this.文献ToolStripMenuItem, this.编辑颜色ToolStripMenuItem, this.有关ToolStripMenuItem); this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1" this.menuStrip1.Size = new System.Drawing.Size(305, 24); this.menuStrip1.TabIndex = 0; this.menuStrip1.Text = "menuStrip1" / / 文献ToolStripMenuItem / this.文献ToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem this.Open, this.NEW, this.saveFile, this.Exist); this.文献ToolStripMenuItem.Name = "文献ToolStripMenuItem" this.文献ToolStripMenuItem.Size = new System.Drawing.Size(43, 20); this.文献ToolStripMenuItem.Text = "文献" / / Open / this.Open.Name = "Open" this.Open.Size = new System.Drawing.Size(98, 22); this.Open.Text = "打开" this.Open.Click += new System.EventHandler(this.Open_Click); / / NEW / this.NEW.Name = "NEW" this.NEW.Size = new System.Drawing.Size(98, 22); this.NEW.Text = "新建" this.NEW.Click += new System.EventHandler(this.NEW_Click); / / saveFile / this.saveFile.Name = "saveFile" this.saveFile.Size = new System.Drawing.Size(98, 22); this.saveFile.Text = "保留" this.saveFile.Click += new System.EventHandler(this.saveFile_Click); / / Exist / this.Exist.Name = "Exist" this.Exist.Size = new System.Drawing.Size(98, 22); this.Exist.Text = "退出" this.Exist.Click+= new System.EventHandler(this. Exist_Click); / / 编辑颜色ToolStripMenuItem / this.编辑颜色ToolStripMenuItem.Name = "编辑颜色ToolStripMenuItem" this.编辑颜色ToolStripMenuItem.Size = new System.Drawing.Size(67, 20); this.编辑颜色ToolStripMenuItem.Text = "编辑颜色" this.编辑颜色ToolStripMenuItem.Click += new System.EventHandler(this.编辑颜色ToolStripMenuItem_Click); / / 有关ToolStripMenuItem / this.有关ToolStripMenuItem.Name = "有关ToolStripMenuItem" this.有关ToolStripMenuItem.Size = new System.Drawing.Size(43, 20); this.有关ToolStripMenuItem.Text = "有关" this.有关ToolStripMenuItem.Click += new System.EventHandler(this.有关ToolStripMenuItem_Click); / / toolTip1 / this.toolTip1.ShowAlways = true; / / menuStrip2 / this.menuStrip2.Dock = System.Windows.Forms.DockStyle.Bottom; this.menuStrip2.Enabled = false; this.menuStrip2.GripStyle = System.Windows.Forms.ToolStripGripStyle.Visible; this.menuStrip2.Items.AddRange(new System.Windows.Forms.ToolStripItem this.画笔工具ToolStripMenuItem, this.画直线ToolStripMenuItem, this.画椭圆ToolStripMenuItem, this.画矩形ToolStripMenuItem, this.橡皮擦ToolStripMenuItem, this.鼠标ToolStripMenuItem); this.menuStrip2.Location = new System.Drawing.Point(0, 332); this.menuStrip2.Name = "menuStrip2" this.menuStrip2.Size = new System.Drawing.Size(305, 24); this.menuStrip2.TabIndex = 1; this.menuStrip2.Text = "menuStrip2" this.menuStrip2.ItemClicked += new System.Windows.Forms.ToolStripItemClickedEventHandler(this.menuStrip2_ItemClicked); / / 画笔工具ToolStripMenuItem / this.画笔工具ToolStripMenuItem.Name = "画笔工具ToolStripMenuItem" this.画笔工具ToolStripMenuItem.Size = new System.Drawing.Size(43, 20); this.画笔工具ToolStripMenuItem.Text = "画笔" / / 画直线ToolStripMenuItem / this.画直线ToolStripMenuItem.Name = "画直线ToolStripMenuItem" this.画直线ToolStripMenuItem.Size = new System.Drawing.Size(55, 20); this.画直线ToolStripMenuItem.Text = "画直线" / / 画椭圆ToolStripMenuItem / this.画椭圆ToolStripMenuItem.Name = "画椭圆ToolStripMenuItem" this.画椭圆ToolStripMenuItem.Size = new System.Drawing.Size(55, 20); this.画椭圆ToolStripMenuItem.Text = "画椭圆" / / 画矩形ToolStripMenuItem / this.画矩形ToolStripMenuItem.Name = "画矩形ToolStripMenuItem" this.画矩形ToolStripMenuItem.Size = new System.Drawing.Size(55, 20); this.画矩形ToolStripMenuItem.Text = "画矩形" / / 橡皮擦ToolStripMenuItem / this.橡皮擦ToolStripMenuItem.Name = "橡皮擦ToolStripMenuItem" this.橡皮擦ToolStripMenuItem.Size = new System.Drawing.Size(55, 20); this.橡皮擦ToolStripMenuItem.Text = "橡皮擦" / / 鼠标ToolStripMenuItem / this.鼠标ToolStripMenuItem.Name = "鼠标ToolStripMenuItem" this.鼠标ToolStripMenuItem.Size = new System.Drawing.Size(43, 20); this.鼠标ToolStripMenuItem.Text = "鼠标" / / openFiles / this.openFiles.FileName = "图像文献" / / panel1 / this.panel1.Controls.Add(this.label1); this.panel1.Controls.Add(this.button1); this.panel1.Location = new System.Drawing.Point(12, 59); this.panel1.Name = "panel1" this.panel1.Size = new System.Drawing.Size(281, 131); this.panel1.TabIndex = 2; this.panel1.Visible = false; / / label1 / this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Point(3, 29); this.label1.Name = "label1" this.label1.Size = new System.Drawing.Size(275, 12); this.label1.TabIndex = 1; this.label1.Text = "更多资料到查看?/zhouxiaoming" / / button1 / this.button1.Location = new System.Drawing.Point(121, 105); this.button1.Name = "button1" this.button1.Size = new System.Drawing.Size(75, 23); this.button1.TabIndex = 0; this.button1.Text = "关闭" this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.button1_Click); / / Form1 / this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(305, 356); this.Controls.Add(this.panel1); this.Controls.Add(this.menuStrip1); this.Controls.Add(this.menuStrip2); this.Cursor = System.Windows.Forms.Cursors.Default; this.MainMenuStrip = this.menuStrip1; this.Name = "Form1" this.Text = "Form1" this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint); this.SizeChanged += new System.EventHandler(this.Form1_SizeChanged); this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseUp); this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseMove); this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseDown); this.menuStrip1.ResumeLayout(false); this.menuStrip1.PerformLayout(); this.menuStrip2.ResumeLayout(false); this.menuStrip2.PerformLayout(); this.panel1.ResumeLayout(false); this.panel1.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); #endregion private System.Windows.Forms.MenuStrip menuStrip1; private System.Windows.Forms.ToolStripMenuItem 文献ToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem Open; private System.Windows.Forms.ToolStripMenuItem NEW; private System.Windows.Forms.ToolStripMenuItem saveFile; private System.Windows.Forms.ToolStripMenuItem Exist; private System.Windows.Forms.ToolStripMenuItem 编辑颜色ToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem 有关ToolStripMenuItem; private System.Windows.Forms.ToolTip toolTip1; private System.Windows.Forms.MenuStrip menuStrip2; private System.Windows.Forms.ToolStripMenuItem 画笔工具ToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem 画直线ToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem 画矩形ToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem 画椭圆ToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem 橡皮擦ToolStripMenuItem; private System.Windows.Forms.SaveFileDialog saveFiles; private System.Windows.Forms.OpenFileDialog openFiles; private System.Windows.Forms.ToolStripMenuItem 鼠标ToolStripMenuItem; private System.Windows.Forms.Panel panel1; private System.Windows.Forms.Label label1; private System.Windows.Forms.Button button1; / <summary> / 应用程序旳主入口点。 / </summary> STAThread static void Main() Application.Run(new Form1(); /布尔型变量,与否正在绘图 private bool isDrawing = false; /绘图时记录鼠标旳位置 private Point startPoint, oldPoint; /枚举类型,多种绘图工具 private enum drawTools Pen = 0, Line, Ellipse, Rectangle, String, Rubber, None ; /目前使用旳工具 private drawTools drawTool = drawTools.None; private string editFileName; private Image theImage; private Graphics ig; private Color foreColor = Color.Black; private Color backColor = Color.White; private int i = 0;/在保留文献是用来标识文献 private void Open_Click(object sender, EventArgs e) openFiles.Filter = "Image Files(*.bmp;*.wmf;*.ico;*.cur;*.jgp)|*.bmp;*.wmf;*.ico;*.cur;*.jpg" openFiles.Multiselect = false; if (openFiles.ShowDialog() = DialogResult.OK) /修改窗口标题 this.Text = openFiles.FileName; editFileName = openFiles.FileName; theImage = Image.FromFile(openFiles.FileName); Graphics g = this.CreateGraphics(); g.DrawImage(theImage, this.ClientRectangle); ig = Graphics.FromImage(theImage); ig.DrawImage(theImage, this.ClientRectangle); menuStrip2.Enabled = true; private void NEW_Click(object sender, EventArgs e) Graphics g = this.CreateGraphics(); g.Clear(backColor); menuStrip2.Enabled = true; /创立一种Bitmap theImage = new Bitmap(this.ClientRectangle.Width, this.ClientRectangle.Height); editFileName = "新建文献" /修改窗口标题 this.Text = editFileName; ig = Graphics.FromImage(theImage); ig.Clear(backColor); private void saveFile_Click(object sender, EventArgs e) saveFiles.Filter = "图像(*.bmp)|*.bmp" saveFiles.FileName = editFileName; if (saveFiles.ShowDialog() = DialogResult.OK) theImage.Save(saveFiles.FileName, ImageFormat.Bmp); this.Text = saveFiles.FileName; editFileName = saveFiles.FileName; i+; private void 编辑颜色ToolStripMenuItem_Click(object sender, EventArgs e) ColorDialog colorDg = new ColorDialog(); if (colorDg.ShowDialog() = DialogResult.OK) foreColor = colorDg.Color; private void menuStrip2_ItemClicked(object sender, ToolStripItemClickedEventArgs e) switch (menuStrip2.Items.IndexOf(e.ClickedItem) case 0: drawTool = drawTools.Pen; this.Cursor = Cursors.Hand; break; case 1: drawTool = drawTools.Line; this.Cursor = Cursors.Cross; break; case 2: drawTool = drawTools.Ellipse; this.Cursor = Cursors.Cross; break; case 3: drawTool = drawTools.Rectangle; this.Cursor = Cursors.Cross; break; case 4: drawTool = drawTools.Rubber; this.Cursor = Cursors.No; break; case 5: drawTool = drawTools.None; this.Cursor = Cursors.Default; break; /鼠标按下 private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) if (e.Button = MouseButtons.Left) if (isDrawing = !isDrawing) = true) startPoint = new Point(e.X, e.Y); oldPoint = new Point(e.X, e.Y); /鼠标移动 private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) Graphics g; g = this.CreateGraphics(); if (isDrawing) switch (drawTool) case drawTools.None: break; case drawTools.Pen: /从上一种点到目前点绘制线段 g.DrawLine(new Pen(foreColor, 1), oldPoint, new Point(e.X, e.Y); ig.DrawLine(new Pen(foreColor, 1), oldPoint, new Point(e.X, e.Y); oldPoint.X = e.X; oldPoint.Y = e.Y; break; case drawTools.Line: /首先恢复本次操作之前旳图像,然后再添加Line this.Form1_Paint(this, new PaintEventArgs(this.CreateGraphics(), this.ClientRectangle); g.DrawLine(new Pen(foreColor, 1), startPoint, new Point(e.X, e.Y); break; case drawTools.Ellipse: /首先恢复本次操作之前旳图像,然后再添加Ellipse this.Form1_Paint(this, new PaintEventArgs(this.CreateGraphics(), this.ClientRectangle); g.DrawEllipse(new Pen(foreColor, 1), startPoint.X, startPoint.Y, e.X - startPoint.X, e.Y - startPoint.Y); break; case drawTools.Rectangle: /首先恢复本次操作之前旳图像,然后再添加Rectangle this.Form1_Paint(this, new PaintEventArgs(this.CreateGraphics(), this.ClientRectangle); g.DrawRectangle(new Pen(foreColor, 1), startPoint.X, startPoint.Y, e.X - startPoint.X, e.Y - startPoint.Y); break; case drawTools.Rubber: /用背景色绘制宽线段 g.DrawLine(new Pen(backColor, 20), oldPoint, new Point(e.X, e.Y); ig.DrawLine(new Pen(backColor, 20), oldPoint, new Point(e.X, e.Y); oldPoint.X = e.X; oldPoint.Y = e.Y; break; /鼠标松开 private void Form1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) isDrawing = false; switch (drawTool) case drawTools.Line: ig.DrawLine(new Pen(foreColor, 1), startPoint, new Point(e.X, e.Y); break; case drawTools.Ellipse: ig.DrawEllipse(new Pen(foreColor, 1), startPoint.X, startPoint.Y, e.X - startPoint.X, e.Y - startPoint.Y); break; case drawTools.Rectangle: ig.DrawRectangle(new Pen(foreColo

注意事项

本文(C#经典实例----画图程序)为本站会员(枕***)主动上传,装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知装配图网(点击联系客服),我们立即给予删除!

温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!