お知らせ

電子会議

ライブラリ

パレット

Delphi FAQ検索

Delphi FAQ一覧

サンプル蔵





FDelphi FAQ
16番会議室「玉石混淆みんなで作るSample蔵」に寄せられたサンプル

"RE:指定のプリンタでPrintDialog表示"

この発言は
#00612 Satobe さんの指定のプリンタでPrintDialog表示
に対するコメントです

◆解説 TPrintDialog で、指定のプリンタを初期値として表示させる。 【「通常使うプリンタ」でないプリンタ】(ややこしい(^^;) の Priきます。 ※前回発言のコードで行っている、TPrintDialogの OnShowイベ ント処理は「まったく不要である」ことが判明しました。(^^; ◆動作確認 Delphi3.1 + Win95a Delphi3.1 + WinNT4.0(SP3) ←この動作も確認しました ◆例 (1) uses に Printers を追加する (2) Form1に ListBox1,Button1,PrintDialog1を置く ----- ここから ----- type TForm1 = class(TForm) ...省略(前回発言の FPrinterName変数も不要です) implementation //Form1 OnCreateイベント procedure TForm1.FormCreate(Sender: TObject); begin ListBox1.Items.Assign(Printer.Printers); //通常使うプリンタを選択 Printer.PrinterIndex := -1; ListBox1.ItemIndex := Printer.PrinterIndex; end; //Button1 OnClickイベント procedure TForm1.But TObject); var Device, Driver, Port: array[0..79] of char; DeviceMode: THandle; begin if ListBox1.ItemIndex < 0 then begin ShowMessage('ListBoxで目的のプリンタを選択して下さい'); Exit; end; //ListBox1で選択されたプリンタの DEVMODE構造体を //TPrinterオブジェクト内部で再取得させる Printer.PrinterIndex := ListBox1.ItemIndex; Printer.GetPrinter(Device, Driver, Port Printer.SetPrinter(Device, Driver, Port, 0); //(*2) Printer.GetPrinter(Device, Driver, Port, DeviceMode); if DeviceMode = 0 then begin ShowMessage('Printer.GetPrinter エラー'); Exit; end; PrintDialog1.Execute; end; ----- ここまで ----- ListBoxで目的のプリンタを選択してから Buttonをクリックして 下さい。 Printer.PrinterIndexプロパティを目的のプリン よいわけです。 Original document by Satobe 氏 ID:(JCG00336)



ここにあるドキュメントは NIFTY SERVEの Delphi Users' Forum の16番会議室「玉石混淆みんなで作るSample蔵」に投稿されたサンプルです。これらのサンプルはボーランド株式会社がサポートする公式のものではありません。また、必ずしも動作が検証されているものではありません。これらのサンプルを使用したことに起因するいかなる損害も投稿者、およびフォーラムスタッフはその責めを負いません。使用者のリスクの範疇でご使用下さい。

Copyright 1996-2002 Delphi Users' Forum