• 大小: 3.06MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-09-15
  • 语言: C#
  • 标签: 打印图片  

资源简介

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个文件信息

评论

共有 条评论