• 大小: 40KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-06
  • 语言: C#
  • 标签: C#  绘图界面  简洁  

资源简介

通过GDI和C#实现简单的绘图界面,可绘画直线、椭圆、矩形等功能,还可以擦除已绘制的图形。菜单包括新建、打开、保存、退出等功能。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        //是否正在绘图
        private bool MyDrawing = false;
        //绘图时记录鼠标位置
        private Point MyStartPoint MyOldPoint;
        //枚举各种绘图工具
        private enum MyDrawModes
        {
            Pen = 0 Line Ellipse Rectangle Rubber None
        };
        //当前使用工具
        private MyDrawModes MyDrawMode = MyDrawModes.None;
        //进行操作的位图
        private Image MyImage;
        //绘制位图实例对象
        private Graphics MyGraphics;
        //绘图使用颜色
        private Color MyForeColor = Color.Black;
        private Color MyBackColor = Color.White;
        private void button1_Click(object sender EventArgs e)
        {//新建
            Graphics g = this.panel2.CreateGraphics();
            g.Clear(MyBackColor);
            MyImage = new Bitmap(this.panel2.ClientRectangle.Widththis.panel2.ClientRectangle.Height);
            MyGraphics = Graphics.FromImage(MyImage);
            MyGraphics.Clear(MyBackColor);
        }
        private void button2_Click(object sender EventArgs e)
        {//打开
            if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                MyImage = Image.FromFile(this.openFileDialog1.FileName);
                Graphics g = this.panel2.CreateGraphics();
                g.DrawImage(MyImage this.panel2.ClientRectangle);
                MyGraphics = Graphics.FromImage(MyImage);
                MyGraphics.DrawImage(MyImage this.panel2.ClientRectangle);
            }
        }
        private void button3_Click(object sender EventArgs e)
        {//保存
            if (this.saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                MyImage.Save(this.saveFileDialog1.FileName + “.bmp“ System.Drawing.Imaging.ImageFormat.Bmp);
            }
        }
        private void button4_Click(object sender EventArgs e)
        {//颜色
            if (this.colorDialog1.ShowDialog() == DialogResult.OK)
            {
                MyForeColor = this.colorDialog1.Color;
            }
        }
        private void button5_Click(object sender EventArgs e)
        {//橡皮
            MyDrawMode = MyDrawModes.Rubber;
        }
        private void button6_Click(object sender EventArgs e)
        {//任意线
            MyDrawMode = MyDrawModes.Pen;
        }
        private void button7_Click(object sender EventArgs e)
        {//直线
            MyDrawMode = MyDrawModes.Line;
        }
        private void button8_Click(object sender EventArgs e)
        {//椭圆
            MyDrawMode = MyDrawModes.Ellipse;
        }
        private void button9_Click(object sender EventArgs e)
        {//矩形
            

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     目录          0  2007-03-18 20:28  绘图GDI+\WindowsApplication1\bin\Debug

     文件       5632  2005-09-23 06:56  绘图GDI+\WindowsApplication1\bin\Release\WindowsApplication1.vshost.exe

     文件      24576  2008-12-16 20:39  绘图GDI+\WindowsApplication1\bin\Release\WindowsApplication1.exe

     文件      26112  2008-12-16 20:39  绘图GDI+\WindowsApplication1\bin\Release\WindowsApplication1.pdb

     目录          0  2007-03-18 20:28  绘图GDI+\WindowsApplication1\bin\Release

     目录          0  2007-03-18 20:28  绘图GDI+\WindowsApplication1\bin

     文件       7775  2007-12-03 22:32  绘图GDI+\WindowsApplication1\Form1.cs

     文件      10195  2007-12-03 22:32  绘图GDI+\WindowsApplication1\Form1.Designer.cs

     文件       6774  2007-12-03 22:32  绘图GDI+\WindowsApplication1\Form1.resx

     目录          0  2008-12-16 20:39  绘图GDI+\WindowsApplication1\obj\Debug\TempPE

     目录          0  2007-03-18 20:28  绘图GDI+\WindowsApplication1\obj\Debug

     目录          0  2008-12-16 20:39  绘图GDI+\WindowsApplication1\obj\Release\TempPE

     文件        499  2008-12-16 20:39  绘图GDI+\WindowsApplication1\obj\Release\WindowsApplication1.Form1.resources

     文件        180  2008-12-16 20:39  绘图GDI+\WindowsApplication1\obj\Release\WindowsApplication1.Properties.Resources.resources

     文件        842  2008-12-16 20:39  绘图GDI+\WindowsApplication1\obj\Release\WindowsApplication1.csproj.GenerateResource.Cache

     文件      26112  2008-12-16 20:39  绘图GDI+\WindowsApplication1\obj\Release\WindowsApplication1.pdb

     文件      24576  2008-12-16 20:39  绘图GDI+\WindowsApplication1\obj\Release\WindowsApplication1.exe

     目录          0  2007-12-02 14:22  绘图GDI+\WindowsApplication1\obj\Release

     文件        368  2008-12-16 20:40  绘图GDI+\WindowsApplication1\obj\WindowsApplication1.csproj.FileList.txt

     目录          0  2007-03-18 20:28  绘图GDI+\WindowsApplication1\obj

     文件        478  2006-05-30 15:27  绘图GDI+\WindowsApplication1\Program.cs

     文件       1210  2006-05-30 15:27  绘图GDI+\WindowsApplication1\Properties\AssemblyInfo.cs

     文件       2892  2006-05-30 15:27  绘图GDI+\WindowsApplication1\Properties\Resources.Designer.cs

     文件       5612  2006-05-30 15:27  绘图GDI+\WindowsApplication1\Properties\Resources.resx

     文件       1102  2006-05-30 15:27  绘图GDI+\WindowsApplication1\Properties\Settings.Designer.cs

     文件        249  2006-05-30 15:27  绘图GDI+\WindowsApplication1\Properties\Settings.settings

     目录          0  2007-03-18 20:28  绘图GDI+\WindowsApplication1\Properties

     文件       3245  2006-05-30 15:28  绘图GDI+\WindowsApplication1\WindowsApplication1.csproj

     目录          0  2007-12-03 22:32  绘图GDI+\WindowsApplication1

     文件        946  2006-05-30 15:27  绘图GDI+\WindowsApplication1.sln

............此处省略5个文件信息

评论

共有 条评论