資源簡介
C#打印機打印指定模塊內容案例,鏈接打印機,打印指定區域內容,將指定區域保存成圖片.

代碼片段和文件信息
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;
namespace?WindowsFormsApplication1
{
????public?partial?class?Form1?:?Form
????{
????????public?Form1()
????????{
????????????InitializeComponent();
????????}
????????[System.Runtime.InteropServices.DllImportAttribute(“gdi32.dll“)]//應用API函數
????????private?static?extern?bool?BitBlt(
????????IntPtr?hdcDest?//?目標設備的句柄?
????????int?nXDest?//?目標對象的左上角的X坐標?
????????int?nYDest?//?目標對象的左上角的X坐標?
????????int?nWidth?//?目標對象的矩形的寬度?
????????int?nHeight?//?目標對象的矩形的長度?
????????IntPtr?hdcSrc?//?源設備的句柄?
????????int?nXSrc?//?源對象的左上角的X坐標?
????????int?nYSrc?//?源對象的左上角的X坐標?
????????System.Int32?dwRop?//?光柵的操作值?
????????);
????????private?void?printDocument1_PrintPage(object?sender?System.Drawing.Printing.PrintPageEventArgs?e)
????????{
????????????Bitmap?bmp?=?new?Bitmap(panel1.Width?panel1.Height);
????????????panel1.DrawToBitmap(bmp?new?Rectangle(Point.Empty?panel1.Size));
????????????e.Graphics.DrawImage(bmp?Point.Empty);
????????}
????????private?void?button1_Click(object?sender?EventArgs?e)
????????{
????????????Graphics?graphic?=?panel1.CreateGraphics();
????????????Size?s?=?panel1.Size;
????????????Bitmap?sourceBitmap?=?new?Bitmap(s.Width?s.Height);
????????????Bitmap?memImage?=?new?Bitmap(s.Width?s.Height?graphic);
????????????Graphics?memGraphic?=?Graphics.FromImage(memImage);
????????????IntPtr?dc1?=?graphic.GetHdc();
????????????IntPtr?dc2?=?memGraphic.GetHdc();
????????????BitBlt(dc2?0?0?panel1.ClientRectangle.Width?panel1.ClientRectangle.Height
??????????????????dc1?0?0?13369376);
????????????//Clone???????the???bitmap???so???we???can???dispose???it.?????
????????????Image?print_image?=?(Image)memImage.Clone();
????????????graphic.ReleaseHdc(dc1);
????????????memGraphic.ReleaseHdc(dc2);
????????????graphic.Dispose();
????????????memGraphic.Dispose();
????????????//memImage.Dispose();
????????????PrintPreviewDialog?dlg?=?new?PrintPreviewDialog();
????????????dlg.Width?=?s.Width;
????????????dlg.Height?=?s.Height;
????????????dlg.Document?=?printDocument1;
????????????if?(dlg.ShowDialog()?==?DialogResult.OK)
????????????{
????????????????printDocument1.Print();
????????????????MessageBox.Show(“打印成功!“);
????????????}
????????}
????????private?void?button2_Click(object?sender?EventArgs?e)
????????{
????????????SaveFileDialog?saveFileDialog?=?new?SaveFileDialog();
????????????//設置文件類型?
????????????saveFileDialog.Filter?=?“圖片保存路徑(*.jpg)|*.jpg“;
????????????//設置默認文件類型顯示順序?
????????????saveFileDialog.FilterIndex?=?1;
????????????//保存對話框是否記憶上次打開的目錄?
????????????saveFileDialog.RestoreDirectory?=?true;
????????????if?(saveFileDialog.ShowDialog()?==?DialogResult.OK)
????????????{
????????????????Graphics?g1?=?panel1.CreateGraphics();
????????????????Image?myImage?=?new?Bitmap(th
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????790016??2013-09-11?18:03??C#打印機打印指定模塊內容案例\C#打印機打印指定模塊內容案例\WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.exe
?????文件??????28160??2013-09-11?18:03??C#打印機打印指定模塊內容案例\C#打印機打印指定模塊內容案例\WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.pdb
?????文件??????11600??2013-09-11?18:04??C#打印機打印指定模塊內容案例\C#打印機打印指定模塊內容案例\WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.vshost.exe
?????文件????????490??2010-03-17?22:39??C#打印機打印指定模塊內容案例\C#打印機打印指定模塊內容案例\WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.vshost.exe.manifest
?????文件???????3787??2013-09-11?18:03??C#打印機打印指定模塊內容案例\C#打印機打印指定模塊內容案例\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs
?????文件???????4774??2013-09-11?17:56??C#打印機打印指定模塊內容案例\C#打印機打印指定模塊內容案例\WindowsFormsApplication1\WindowsFormsApplication1\Form1.Designer.cs
?????文件????1173041??2013-09-11?17:56??C#打印機打印指定模塊內容案例\C#打印機打印指定模塊內容案例\WindowsFormsApplication1\WindowsFormsApplication1\Form1.resx
?????文件???????2164??2013-09-11?17:21??C#打印機打印指定模塊內容案例\C#打印機打印指定模塊內容案例\WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache
?????文件???????6641??2013-09-11?18:03??C#打印機打印指定模塊內容案例\C#打印機打印指定模塊內容案例\WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件???????1268??2013-09-11?17:57??C#打印機打印指定模塊內容案例\C#打印機打印指定模塊內容案例\WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\GenerateResource.read.1.tlog
?????文件???????2066??2013-09-11?17:57??C#打印機打印指定模塊內容案例\C#打印機打印指定模塊內容案例\WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\GenerateResource.write.1.tlog
?????文件???????2939??2013-09-11?18:04??C#打印機打印指定模塊內容案例\C#打印機打印指定模塊內容案例\WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.csproj.FileListAbsolute.txt
?????文件?????790016??2013-09-11?18:03??C#打印機打印指定模塊內容案例\C#打印機打印指定模塊內容案例\WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.exe
?????文件?????778307??2013-09-11?17:57??C#打印機打印指定模塊內容案例\C#打印機打印指定模塊內容案例\WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.Form1.resources
?????文件??????28160??2013-09-11?18:03??C#打印機打印指定模塊內容案例\C#打印機打印指定模塊內容案例\WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.pdb
?????文件????????180??2013-09-11?17:57??C#打印機打印指定模塊內容案例\C#打印機打印指定模塊內容案例\WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.Properties.Resources.resources
?????文件????????505??2013-09-11?17:21??C#打印機打印指定模塊內容案例\C#打印機打印指定模塊內容案例\WindowsFormsApplication1\WindowsFormsApplication1\Program.cs
?????文件???????1398??2013-09-11?17:21??C#打印機打印指定模塊內容案例\C#打印機打印指定模塊內容案例\WindowsFormsApplication1\WindowsFormsApplication1\Properties\AssemblyInfo.cs
?????文件???????2899??2013-09-11?17:21??C#打印機打印指定模塊內容案例\C#打印機打印指定模塊內容案例\WindowsFormsApplication1\WindowsFormsApplication1\Properties\Resources.Designer.cs
?????文件???????5612??2013-09-11?17:21??C#打印機打印指定模塊內容案例\C#打印機打印指定模塊內容案例\WindowsFormsApplication1\WindowsFormsApplication1\Properties\Resources.resx
?????文件???????1110??2013-09-11?17:21??C#打印機打印指定模塊內容案例\C#打印機打印指定模塊內容案例\WindowsFormsApplication1\WindowsFormsApplication1\Properties\Settings.Designer.cs
?????文件????????249??2013-09-11?17:21??C#打印機打印指定模塊內容案例\C#打印機打印指定模塊內容案例\WindowsFormsApplication1\WindowsFormsApplication1\Properties\Settings.settings
?????文件???????3707??2013-09-11?17:22??C#打印機打印指定模塊內容案例\C#打印機打印指定模塊內容案例\WindowsFormsApplication1\WindowsFormsApplication1\WindowsFormsApplication1.csproj
?????文件????????914??2013-09-11?17:21??C#打印機打印指定模塊內容案例\C#打印機打印指定模塊內容案例\WindowsFormsApplication1\WindowsFormsApplication1.sln
????..A..H.?????20992??2013-09-11?18:04??C#打印機打印指定模塊內容案例\C#打印機打印指定模塊內容案例\WindowsFormsApplication1\WindowsFormsApplication1.suo
?????目錄??????????0??2013-09-11?17:21??C#打印機打印指定模塊內容案例\C#打印機打印指定模塊內容案例\WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\TempPE
?????目錄??????????0??2013-09-11?18:03??C#打印機打印指定模塊內容案例\C#打印機打印指定模塊內容案例\WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug
?????目錄??????????0??2013-09-11?17:25??C#打印機打印指定模塊內容案例\C#打印機打印指定模塊內容案例\WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug
?????目錄??????????0??2013-09-11?17:21??C#打印機打印指定模塊內容案例\C#打印機打印指定模塊內容案例\WindowsFormsApplication1\WindowsFormsApplication1\obj\x86
?????目錄??????????0??2013-09-11?17:21??C#打印機打印指定模塊內容案例\C#打印機打印指定模塊內容案例\WindowsFormsApplication1\WindowsFormsApplication1\bin
............此處省略9個文件信息
- 上一篇:C#程序防止反編譯工具
- 下一篇:C#超市進銷存銷售管理系統
評論
共有 條評論