窗体上有个TComBox,命名为cb1
窗体名为Form1procedure TForm1.FormCreate(Sender: TObject);
begin
cb1.items.assign(printer.printers);
end;procedure TForm1.Button1Click(Sender: TObject);
var LPrinter:string;
PrinIniFile:Tinifile;
LStr:string;
begin
LStr:=printer.Printers[cb1.itemindex];
delete(Lstr,pos(' on ',Lstr),Length(LStr));
PrinIniFile:=TIniFile.Create('WIN.ini');
try
LPrinter:=PrinIniFile.ReadString('Devices',LStr,'');
PrinIniFile.writestring('windows','device',LStr+','+LPrinter);
finally
PrinIniFile.free;
end;
end;
窗体名为Form1procedure TForm1.FormCreate(Sender: TObject);
begin
cb1.items.assign(printer.printers);
end;procedure TForm1.Button1Click(Sender: TObject);
var LPrinter:string;
PrinIniFile:Tinifile;
LStr:string;
begin
LStr:=printer.Printers[cb1.itemindex];
delete(Lstr,pos(' on ',Lstr),Length(LStr));
PrinIniFile:=TIniFile.Create('WIN.ini');
try
LPrinter:=PrinIniFile.ReadString('Devices',LStr,'');
PrinIniFile.writestring('windows','device',LStr+','+LPrinter);
finally
PrinIniFile.free;
end;
end;
解决方案 »
- 关于使用webbrowser控件获得网页信息的内容
- idhttp 提交表单的问题
- 找DELPHI4下载(收藏用)
- tquery调用数据库要求输入密码,不知道怎样和解决?急
- 三层应用中一个奇怪的问题!!不知道你遇到过吗??
- 请问imageen控件 里面的控件能不能实现鼠标滚轮放大或缩小控件本身的长各宽?
- delphi7.0 和 delphi V7.0 是同一个版本吗,他们有什么区别?
- 哪有1stclass4000,InfoPower4000的安装密码下载?急??????????????
- windows消息的小问题
- 这条语句为什么是错误的:adoquery1.sql.add('where mc like ''%'+trim(edit1.text)+'%''');解决后立即发分
- 怎样用程序实现设置默认打印机
- ado的速度
我用的系统是Win2000,这样做行吗?
在窗体中加入combobox和两个button
你自己TRY!
我测试通过!procedure TForm1.Button1Click(Sender: TObject);
begin
ComboBox1.Items := Printer.Printers; {populates ComboBox}
ComboBox1.ItemIndex := Printer.PrinterIndex; {sets display to current printer}
end;procedure TForm1.Button2Click(Sender: TObject);
var
Device: array[0..255] of Char;
Driver: array[0..255] of char;
Port: array[0..255] of char;
s : array[0..255] of Char;
hDeviceMode: THandle;begin Printer.PrinterIndex := ComboBox1.ItemIndex;
Printer.GetPrinter (Device, Driver, Port, hDeviceMode);
StrCopy (s, Device);
StrCat (s, ',');
StrCat (s, Driver);
StrCat (s, ',');
StrCat (s, Port);
WriteProfileString ('windows', 'device', s);
StrCopy (s, 'windows');
SendMessage (HWND_BROADCAST, WM_WININICHANGE, 0, LongInt(@s));end;