(转)设置默认打印机

type
TForm1 = class(TForm)
Button1: TButton;
ComboBox1: TComboBox;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

{...}

procedure TForm1.FormCreate(Sender: TObject);
begin
{ tell printer to go to the default by setting
the PrinterIndex value to -1 告诉打印机到默认设置
到 printerindex=-1}
Printer.PrinterIndex := -1;

{ make our combobox non-editable 让我们的组合框不可编辑的}
ComboBox1.Style := csDropDownList;

{ set our combobox items to the printer printers 设置我们的组合框项显示打印机打印机}
ComboBox1.Items := Printer.Printers;

{ set combobox to view the default printer according to printer printerindex as set above 设置组合框查看默认打印机
根据以上printerindex设置打印机}
ComboBox1.ItemIndex := Printer.PrinterIndex;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
MyHandle : THandle;
MyDevice,
MyDriver,
MyPort: array [0..255] of Char;
begin
{ set printer to the selected according to the
combobox itemendex 将打印机设置为根据
组合框itemendex}
Printer.PrinterIndex := ComboBox1.ItemIndex;

{ get our printer properties 获取打印机属性}
Printer.GetPrinter(MyDevice,
MyDriver,
MyPort,
MyHandle);

{ create string of exactly what WriteProfileString()
wants to see by concat each of the above received
character arrays 创建接收WriteProfileString()字符串到的字符数组 }
StrCat( MyDevice, ‘,‘);
StrCat( MyDevice, MyDriver );
StrCat( MyDevice, ‘,‘);
StrCat( MyDevice, MyPort );

{ copy our new default printer into our windows ini file
to the [WINDOWS] section under DEVICE=
复制我们的新默认打印机到我们的Windows INI文件到windows部分下的DEVICE}
WriteProfileString(‘WINDOWS‘,
‘DEVICE‘,
MyDevice );

{ tell all applications that the windows ini file has
changed, this will cause them all to recheck default
printer 告诉所有的Windows INI文件的应用程序
改变,这将使他们所有的核对默认
打印机}
SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0, LongInt(pChar(‘windows‘)));
end;
end;

时间: 2024-10-17 01:37:28

(转)设置默认打印机的相关文章

C#设置默认打印机

开发中经常会遇到需要用到打印机的问题,那么我们现在来一个Demo修改系统默认打印机.先看运行效果吧.(主要为了展示代码和功能,界面就随便拖拉了一个,比较丑,不要介意.) 界面构建非常简单,首先新建一个Form窗体,拉一个comboBox控件和一个Button然后就可以了. 接下来我们看下代码. 首先是加载本地打印机的类LocalPrinter using System; using System.Collections.Generic; using System.Linq; using Syst

Winform 判断打印机是否可用,实现设置默认打印机功能

Winform 判断打印机是否可用,实现设置默认打印机功能 http://www.cnblogs.com/zfanlong1314/p/3878563.html

winform设置默认打印机

/// <summary> /// 设置默认打印机 /// </summary> public class Externs { [DllImport("winspool.drv")] public static extern bool SetDefaultPrinter(String Name); //调用win api将指定名称的打印机设置为默认打印机 } Externs.SetDefaultPrinter("Microsoft Shared Fax

C#Winfrom系统打印机调用/设置默认打印机

实现如下效果: 实现方式如下: using System;using System.Drawing.Printing;using System.Runtime.InteropServices;using System.Windows.Forms; namespace PISS.View.CustomControl{ public partial class PrinterConfigMessBox : Form { #region 定义.构造.初始化 [DllImport("winspool.d

怎样设置默认打印机(HttpPrinter 易桥网络打印机)

1.把 报表绑定打印机 2.客户端打印时 指定打印机, 控制面板中 可以查看您的 打印机的名称 下面的 "PrinterName": encodeURIComponent("打印机名称"), 改为 "PrinterName": encodeURIComponent("EPSON LQ-630K ESC/P2") {"ReportName": encodeURIComponent("test.grf

C#获取本地打印机列表,并将指定打印机设置为默认打印机

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Med

如何以编程方式打印到在 MFC 中的非默认打印机

http://cache.baiducontent.com/c?m=9f65cb4a8c8507ed4fece763105790245b09c0252bd7a74a2485d315d2390f07506694ea7a7d0d5d83d87f6305ac4957f7b86c65377571eb8f8dd50a8bb485582a9f5631671df65663d50edcba5154cb37e12efeae69f0caf625e7aec5a5de4320c944040a9780fb4d7467&p

C# winForm 修改默认打印机(效果不太好,每次修改都会有一个系统的打印弹窗(win10))

1.界面:1个按钮+1个combobox; 2.开头阴影 using System.Runtime.InteropServices; 3.代码 private void Form1_Load(object sender, EventArgs e) { InitprinterComboBox(); //初始化打印机下拉列表选项 } private void InitprinterComboBox() {// 初始化打印机列表 PrintDocument printDocument = new Pr

C# 默认打印机设置

private void frmBarCode_Load(object sender, EventArgs e) { bindCbox(): } #region 选择打印机 [DllImport("winspool.drv")] public static extern bool SetDefaultPrinter(String Name); //调用win api将指定名称的打印机设置为默认打印机 private static PrintDocument fPrintDocument