資源簡(jiǎn)介
文件導(dǎo)出時(shí)進(jìn)度條顯示其導(dǎo)出的進(jìn)度。利用委托和事件,使窗體避免造成假死狀態(tài)。是理解進(jìn)度條比較好的案例

代碼片段和文件信息
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.Threading;
namespace?ProgressBarTest
{
????public?partial?class?Catch?:?Form
????{
????????public?Catch()
????????{
????????????InitializeComponent();
????????}
????????#region?用戶(hù)變量
????????Point?DownPoint?=?Point.Empty;?//記錄按下鼠標(biāo)時(shí)的坐標(biāo)
????????bool?CatchFinished?=?false;????//表示是否完成截圖
????????bool?CatchStart?=?false;???????//表示截圖開(kāi)始
????????Bitmap?originBmp;??????????????//用來(lái)保存原始的圖像
????????Rectangle?CatchRect;???????????//用來(lái)保存截圖的矩形
????????#endregion
????????private?void?Catch_Load(object?sender?EventArgs?e)
????????{
????????????this.Setstyle(Controlstyles.OptimizedDoubleBuffer?|?Controlstyles.AllPaintingInWmPaint?|?Controlstyles.UserPaint?true);
????????????this.Updatestyles();
????????????Bitmap?CatchBmp?=?new?Bitmap(Screen.AllScreens[0].Bounds.Width?Screen.AllScreens[0].Bounds.Height);//新建一個(gè)和屏幕大小相同的圖片
????????????this.BackgroundImage?=?CatchBmp;
????????????originBmp?=?new?Bitmap(this.BackgroundImage);
????????}
????????private?void?Catch_MouseClick(object?sender?MouseEventArgs?e)
????????{
????????????if?(e.Button?==?MouseButtons.Right)
????????????{
????????????????this.DialogResult?=?DialogResult.OK;
????????????????this.Close();
????????????}
????????}
????????private?void?Catch_MouseDown(object?sender?MouseEventArgs?e)
????????{
????????????if?(e.Button?==?MouseButtons.Left)
????????????{
????????????????if?(!CatchStart)
????????????????{
????????????????????CatchStart?=?true;
????????????????????DownPoint?=?new?Point(e.X?e.Y);
????????????????}
????????????}
????????}
????????private?void?Catch_MouseMove(object?sender?MouseEventArgs?e)
????????{
????????????if?(CatchStart)
????????????{//如果捕捉開(kāi)始
????????????????Bitmap?destBmp?=?(Bitmap)originBmp.Clone();//新建一個(gè)圖片對(duì)象,并讓它與原始圖片相同
????????????????Point?newPoint?=?new?Point(DownPoint.X?DownPoint.Y);//獲取鼠標(biāo)的坐標(biāo)
????????????????Graphics?g?=?Graphics.FromImage(destBmp);//在剛才新建的圖片上新建一個(gè)畫(huà)板
????????????????Pen?p?=?new?Pen(Color.Blue?1);
????????????????int?width?=?Math.Abs(e.X?-?DownPoint.X)?height?=?Math.Abs(e.Y?-?DownPoint.Y);//獲取矩形的長(zhǎng)和寬
????????????????if?(e.X?????????????????{
????????????????????newPoint.X?=?e.X;
????????????????}
????????????????if?(e.Y?????????????????{
????????????????????newPoint.Y?=?e.Y;
????????????????}
????????????????CatchRect?=?new?Rectangle(newPoint?new?Size(width?height));//保存矩形
????????????????g.DrawRectangle(p?CatchRect);//將矩形畫(huà)在這個(gè)畫(huà)板上
????????????????g.Dispose();//釋放目前的這個(gè)畫(huà)板
????????????????p.Dispose();
????????????????Graphics?g1?=?this.CreateGraphics();//重新新建一個(gè)Graphics類(lèi)
????????????????//如果之前那個(gè)畫(huà)板不釋放,而直接g=this.CreateGraphics()這樣的話(huà)無(wú)法釋放掉第一次創(chuàng)建的g因?yàn)橹皇前训刂忿D(zhuǎn)到新的g了.如同string一樣
????????????????g1?=?this.CreateGraphics();//在整個(gè)全屏窗體上新建畫(huà)板
????????????????g1.DrawImag
?屬性????????????大小?????日期????時(shí)間???名稱(chēng)
-----------?---------??----------?-----??----
?????文件???73761344??2012-05-28?21:00??Works\bin\Debug\FileTxt.txt
?????文件????????176??2012-03-03?16:53??Works\bin\Debug\MyFile.bin
?????文件??????14848??2012-07-24?14:43??Works\bin\Debug\ProgressBarTest.exe
?????文件??????26112??2012-07-24?14:43??Works\bin\Debug\ProgressBarTest.pdb
?????文件??????14328??2012-07-24?14:41??Works\bin\Debug\ProgressBarTest.vshost.exe
?????文件????????490??2007-07-21?02:33??Works\bin\Debug\ProgressBarTest.vshost.exe.manifest
?????文件??????18944??2012-03-12?16:02??Works\bin\Debug\進(jìn)度條測(cè)試.exe
?????文件??????44544??2012-03-12?16:02??Works\bin\Debug\進(jìn)度條測(cè)試.pdb
?????文件????????490??2007-07-21?02:33??Works\bin\Debug\進(jìn)度條測(cè)試.vshost.exe.manifest
?????文件???????6689??2012-05-21?11:59??Works\Catch.cs
?????文件???????3328??2012-05-21?11:59??Works\Catch.Designer.cs
?????文件???????5814??2012-05-21?11:59??Works\Catch.resx
?????文件???????7230??2012-05-18?15:01??Works\ExcelReport.cs
?????文件???????9998??2012-05-18?15:01??Works\ExcelReport.Designer.cs
?????文件???????8020??2012-05-18?15:01??Works\ExcelReport.resx
?????文件???????2014??2012-05-22?18:08??Works\GDITest.cs
?????文件???????1583??2012-05-18?17:33??Works\GDITest.Designer.cs
?????文件???????5814??2012-05-18?17:33??Works\GDITest.resx
?????文件???????1354??2012-07-24?14:43??Works\obj\Debug\ProgressBarTest.csproj.FileListAbsolute.txt
?????文件????????853??2012-07-24?14:42??Works\obj\Debug\ProgressBarTest.csproj.GenerateResource.Cache
?????文件????????180??2012-07-24?14:42??Works\obj\Debug\ProgressBarTest.ExcelReport.resources
?????文件??????14848??2012-07-24?14:43??Works\obj\Debug\ProgressBarTest.exe
?????文件??????26112??2012-07-24?14:43??Works\obj\Debug\ProgressBarTest.pdb
?????文件????????180??2012-07-24?14:42??Works\obj\Debug\ProgressBarTest.Properties.Resources.resources
?????文件???????4608??2012-03-12?16:10??Works\obj\Debug\TempPE\Properties.Resources.Designer.cs.dll
?????文件????????757??2012-03-12?16:02??Works\obj\Debug\進(jìn)度條測(cè)試.csproj.FileListAbsolute.txt
?????文件????????990??2012-03-12?15:30??Works\obj\Debug\進(jìn)度條測(cè)試.csproj.GenerateResource.Cache
?????文件??????18944??2012-03-12?16:02??Works\obj\Debug\進(jìn)度條測(cè)試.exe
?????文件??????44544??2012-03-12?16:02??Works\obj\Debug\進(jìn)度條測(cè)試.pdb
?????文件????????180??2012-03-12?10:31??Works\obj\Debug\進(jìn)度條測(cè)試.Properties.Resources.resources
............此處省略25個(gè)文件信息
評(píng)論
共有 條評(píng)論