我想做一个打印的小测试程序,mainform 顶端有个listbox,并有 CbxPrinter.Items := printer.Printers 加上所有的打印机信息。在listbox下面有一个editbox,底部是两个button, print and exit。当user 点击print button, 程序将用listbox中user选中的printer,来打印editbox中的text。仅此而已,只要白纸黑字能打出来就行。周末加班都不容易呀, 希望大家帮忙, 谢谢!
调试欢乐多
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));
ComboBox1.Items := Printer.Printers; {populates ComboBox}
ComboBox1.ItemIndex := Printer.PrinterIndex;
end;procedure TForm1.ComboBox1Change(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;
以上为列表当前系统中所安装的打印及选择打印机的程序,在DELPHI6+WIN2000
下通过。
打印EDITBOX中的内容可用以下程序完成:
uses printers;with printer do
begin
beginDoc;
canvas.Font.Name:='宋体';
canvas.Font.style:=[FsBold];
canvas.Font.size:=11;
canvas.Textout(100,120,'你要打的内容'); //100 距水平 120 距垂直
EndDoc;
end;