資源簡介
這是用C# GDI實現的簡易畫板Demo,對應博文http://blog.csdn.net/luols/article/details/7171668,有需要的朋友可以下載樣例試用

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Text;
using?System.Windows.Forms;
using?System.Drawing.Drawing2D;
namespace?GDIDemo
{
????public?partial?class?Form1?:?Form
????{
????????Bitmap?originImg;
????????Image?finishImg;
????????Graphics?g;
????????DrawType?dType;
????????Point?StartPoint?EndPoint?FontPoint;
????????Pen?p?=?new?Pen(Color.Black?1);
????????bool?IsDraw;
????????Font?font;
????????Rectangle?FontRect;
????????///???
????????///?畫筆顏色??
????????///? ??
????????Color?DrawColor
????????{
????????????get?{?return?p.Color;?}
????????????set?{?p.Color?=?value;?}
????????}
????????///???
????????///?畫筆寬度??
????????///? ??
????????float?PenWidth
????????{
????????????set?{?p.Width?=?value;?}
????????}
????????public?Form1()
????????{
????????????InitializeComponent();
????????????cmbThickness.SelectedIndex?=?0;
????????????//將文本輸入框的父容器設為picDraw,否則顯示時會出現錯位??
????????????txtWrite.Parent?=?picDraw;
????????????this.Setstyle(Controlstyles.OptimizedDoubleBuffer?|?Controlstyles.AllPaintingInWmPaint?|?Controlstyles.UserPaint?true);
????????????this.Updatestyles();
????????????//將線帽樣式設為圓線帽,否則筆寬變寬時會出現明顯的缺口??
????????????p.StartCap?=?LineCap.Round;
????????????p.EndCap?=?LineCap.Round;
????????????originImg?=?new?Bitmap(picDraw.Width?picDraw.Height);
????????????g?=?Graphics.FromImage(originImg);
????????????//畫布背景初始化為白底??
????????????g.Clear(Color.White);
????????????picDraw.Image?=?originImg;
????????????finishImg?=?(Image)originImg.Clone();
????????}
????????private?void?btnArrow_Click(object?sender?EventArgs?e)
????????{
????????????dType?=?DrawType.None;
????????????txtWrite.Visible?=?false;
????????????txtWrite.Text?=?““;
????????}
????????private?void?btnPen_Click(object?sender?EventArgs?e)
????????{
????????????dType?=?DrawType.Pen;
????????????txtWrite.Visible?=?false;
????????????txtWrite.Text?=?““;
????????}
????????private?void?btnLine_Click(object?sender?EventArgs?e)
????????{
????????????dType?=?DrawType.Line;
????????????txtWrite.Visible?=?false;
????????????txtWrite.Text?=?““;
????????}
????????private?void?btnRect_Click(object?sender?EventArgs?e)
????????{
????????????dType?=?DrawType.Rect;
????????????txtWrite.Visible?=?false;
????????????txtWrite.Text?=?““;
????????}
????????private?void?btnEllipse_Click(object?sender?EventArgs?e)
????????{
????????????dType?=?DrawType.Ellipse;
????????????txtWrite.Visible?=?false;
????????????txtWrite.Text?=?““;
????????}
????????private?void?btnEraser_Click(object?sender?EventArgs?e)
????????{
????????????dType?=?DrawType.Eraser;
????????????txtWrite.Visible?=?false;
????????????txtWrite.Text?=?““;
????????}
????????private?void?btnWrite_Click(object?sender?EventArgs?e)
????????{
????????????dType?=?DrawType.Write;
????????????FontDialog?fd?=?ne
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????17408??2015-06-30?11:15??GDIDemo\bin\Debug\GDIDemo.exe
?????文件??????34304??2015-06-30?11:15??GDIDemo\bin\Debug\GDIDemo.pdb
?????文件??????11608??2015-06-30?11:15??GDIDemo\bin\Debug\GDIDemo.vshost.exe
?????文件????????490??2013-03-18?17:00??GDIDemo\bin\Debug\GDIDemo.vshost.exe.manifest
?????文件??????11529??2015-06-30?11:15??GDIDemo\Form1.cs
?????文件??????11691??2015-06-30?11:15??GDIDemo\Form1.Designer.cs
?????文件???????5817??2015-06-30?11:15??GDIDemo\Form1.resx
?????文件???????3421??2015-06-30?11:03??GDIDemo\GDIDemo.csproj
?????文件???????5452??2015-06-30?11:15??GDIDemo\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件????????834??2015-06-30?11:15??GDIDemo\obj\x86\Debug\GDIDemo.csproj.FileListAbsolute.txt
?????文件????????975??2015-06-30?11:15??GDIDemo\obj\x86\Debug\GDIDemo.csproj.GenerateResource.Cache
?????文件??????17408??2015-06-30?11:15??GDIDemo\obj\x86\Debug\GDIDemo.exe
?????文件????????180??2015-06-30?11:15??GDIDemo\obj\x86\Debug\GDIDemo.Form1.resources
?????文件??????34304??2015-06-30?11:15??GDIDemo\obj\x86\Debug\GDIDemo.pdb
?????文件????????180??2015-06-30?11:11??GDIDemo\obj\x86\Debug\GDIDemo.Properties.Resources.resources
?????文件????????468??2015-06-30?10:53??GDIDemo\Program.cs
?????文件???????1364??2015-06-30?10:53??GDIDemo\Properties\AssemblyInfo.cs
?????文件???????2866??2015-06-30?10:53??GDIDemo\Properties\Resources.Designer.cs
?????文件???????5612??2015-06-30?10:53??GDIDemo\Properties\Resources.resx
?????文件???????1094??2015-06-30?10:53??GDIDemo\Properties\Settings.Designer.cs
?????文件????????249??2015-06-30?10:53??GDIDemo\Properties\Settings.settings
?????目錄??????????0??2015-06-30?10:53??GDIDemo\obj\x86\Debug\TempPE
?????目錄??????????0??2015-06-30?11:15??GDIDemo\obj\x86\Debug
?????目錄??????????0??2015-06-30?11:11??GDIDemo\bin\Debug
?????目錄??????????0??2015-06-30?10:53??GDIDemo\obj\x86
?????目錄??????????0??2015-06-30?10:53??GDIDemo\bin
?????目錄??????????0??2015-06-30?10:53??GDIDemo\obj
?????目錄??????????0??2015-06-30?10:53??GDIDemo\Properties
?????目錄??????????0??2015-06-30?10:54??GDIDemo
-----------?---------??----------?-----??----
............此處省略2個文件信息
評論
共有 條評論