線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:4294
推到 Plurk!
推到 Facebook!

QuickRep如何動能設定紙張大小,及取得紙張大小清單??

尚未結案
jeffreck
高階會員


發表:247
回覆:340
積分:197
註冊:2003-01-23

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-02-19 02:05:02 IP:61.70.xxx.xxx 未訂閱
請教各位前輩 QuickRep如何動能設定紙張大小,及取得紙張大小清單?? 我在報表中要給使用者指定紙張大小,如B4.A4.A3 ....等 有何方去可以取得紙張大小清單 且使用者選擇後可以指定到QuickRep1.PrinterSettings.PaperSize 在討論區中有看到 QuickRep1.PrinterSettings.PaperSize:=A4 但這樣就要一行一行寫,A3,B3,B4,B5........... 不知是否有更好的方法?? 謝謝各位前輩
anypro
一般會員


發表:3
回覆:6
積分:1
註冊:2003-12-29

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-02-19 12:38:37 IP:61.155.xxx.xxx 未訂閱
定義紙型 const PaperSize:array[0..27] of TQRPaperSize = (Default, Letter, LetterSmall, Tabloid, Ledger, Legal, Statement, Executive, A3, A4, A4Small, A5, B4, B5, Folio, Quarto, qr10X14, qr11X17, Note, Env9, Env10, Env11, Env12, Env14, CSheet, DSheet, ESheet, Custom); 加入RUN代碼 form.QuickRep1.PrinterSetup; Printers.Printer.GetPrinter(Device, Driver, Port, HDevMode); if HDevMode <> 0 then begin try PDevMode := GlobalLock(HDevMode); papertype := PDevMode.dmPaperSize; if papertype<=26 then form.QuickRep1.Page.PaperSize:=PaperSize[papertype] else begin form.QuickRep1.Page.PaperSize:=PaperSize[27]; //Custome form.QuickRep1.Page.Width:=paperw/10; form.QuickRep1.Page.Length:=paperl/10; ...... finally GlobalUnlock(HDevMode); end;
Miles
尊榮會員


發表:27
回覆:662
積分:622
註冊:2002-07-12

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-02-19 14:29:32 IP:218.160.xxx.xxx 未訂閱
Hi anypro您好: 建議是否可以直接使用一顆TPrinterSetupDialog來做 我不是高手, 高手是正在銀幕前微笑的人.
------


我不是高手, 高手是正在銀幕前微笑的人.
Miles
尊榮會員


發表:27
回覆:662
積分:622
註冊:2002-07-12

發送簡訊給我
#4 引用回覆 回覆 發表時間:2004-02-19 14:54:00 IP:218.160.xxx.xxx 未訂閱
找了一下, 看下面這篇是不是你要的 http://www.mers.com/cgi-bin/mer.exe/EXECSEARCH?searchtext=Paper+Size+List&grouptext=Delphi&pageno=3&linktype=viewmsg&msgno=79215&boardno=740 原文轉貼
procedure GetPapernames( sl: TStrings ); 
Type
   TPaperName = Array [0..63] of Char;
   TPaperNameArray = Array [1..High(Integer) div Sizeof( TPaperName )] of
   TPaperName;
   PPapernameArray = ^TPaperNameArray;
Var 
Device, Driver, Port: Array [0..255] of Char;
hDevMode: THandle; 
i, numPaperformats: Integer; 
pPaperFormats: PPapernameArray; 
begin 
   Printer.PrinterIndex := -1;
   Printer.GetPrinter(Device, Driver, Port, hDevmode);
   numPaperformats :=
   WinSpool.DeviceCapabilities( Device, Port, DC_PAPERNAMES, Nil, Nil );
   If numPaperformats > 0 Then Begin
      GetMem( pPaperformats, numPaperformats * Sizeof( TPapername ));
      try
      WinSpool.DeviceCapabilities( Device, Port, DC_PAPERNAMES,
      Pchar( pPaperFormats ), Nil);
      sl.Clear;
      For i:= 1 To numPaperformats Do
      sl.add( pPaperformats^[i] );
      finally
      FreeMem( pPaperformats );
      end;
   End;
End;
我不是高手, 高手是正在銀幕前微笑的人.
------


我不是高手, 高手是正在銀幕前微笑的人.
jeffreck
高階會員


發表:247
回覆:340
積分:197
註冊:2003-01-23

發送簡訊給我
#5 引用回覆 回覆 發表時間:2004-02-19 16:37:33 IP:61.219.xxx.xxx 未訂閱
引言: Hi anypro您好: 建議是否可以直接使用一顆TPrinterSetupDialog來做 我不是高手, 高手是正在銀幕前微笑的人.
謝謝 Miles 我原本也很想目TPrinterSetupDialog來做 但不知如何吧設定的結果給QuickRep ?? 謝謝前輩
jeffreck
高階會員


發表:247
回覆:340
積分:197
註冊:2003-01-23

發送簡訊給我
#6 引用回覆 回覆 發表時間:2004-02-19 18:02:37 IP:61.219.xxx.xxx 未訂閱
引言: 找了一下, 看下面這篇是不是你要的 http://www.mers.com/cgi-bin/mer.exe/EXECSEARCH?searchtext=Paper+Size+List&grouptext=Delphi&pageno=3&linktype=viewmsg&msgno=79215&boardno=740 原文轉貼
procedure GetPapernames( sl: TStrings ); 
Type
   TPaperName = Array [0..63] of Char;
   TPaperNameArray = Array [1..High(Integer) div Sizeof( TPaperName )] of
   TPaperName;
   PPapernameArray = ^TPaperNameArray;
Var 
Device, Driver, Port: Array [0..255] of Char;
hDevMode: THandle; 
i, numPaperformats: Integer; 
pPaperFormats: PPapernameArray; 
begin 
   Printer.PrinterIndex := -1;
   Printer.GetPrinter(Device, Driver, Port, hDevmode);
   numPaperformats :=
   WinSpool.DeviceCapabilities( Device, Port, DC_PAPERNAMES, Nil, Nil );
   If numPaperformats > 0 Then Begin
      GetMem( pPaperformats, numPaperformats * Sizeof( TPapername ));
      try
      WinSpool.DeviceCapabilities( Device, Port, DC_PAPERNAMES,
      Pchar( pPaperFormats ), Nil);
      sl.Clear;
      For i:= 1 To numPaperformats Do
      sl.add( pPaperformats^[i] );
      finally
      FreeMem( pPaperformats );
      end;
   End;
End;
我不是高手, 高手是正在銀幕前微笑的人.
謝謝Miles 前輩,真是太厲害了!!! 但還有問題,當User 選好紙張大小後如何指定給QuickRep 報表?? 謝謝各位前輩!!
Miles
尊榮會員


發表:27
回覆:662
積分:622
註冊:2002-07-12

發送簡訊給我
#7 引用回覆 回覆 發表時間:2004-02-19 20:46:45 IP:218.160.xxx.xxx 未訂閱
Hi jeffreck 您好: 我在網路上晃了一下發現QuickReport的PaperSize問題還真不少. 參考了一下這一篇, 並將之前程式碼改寫, 整份內容如下, 要注意的是紙張大小會被改掉(印表機-->內容-->列印喜好設定-->進階-->列印紙張大小), 若有需要你在加程式碼改掉即可 http://delphi.ktop.com.tw/topic.php?TOPIC_ID=237
//抓取紙張大小列表
procedure GetPapernames( sl: TStrings );
Type
   TPaperName = Array [0..63] of Char;
   TPaperNameArray = Array [1..High(Integer) div Sizeof( TPaperName )] of
   TPaperName;
   PPapernameArray = ^TPaperNameArray;
Var
Device, Driver, Port: Array [0..255] of Char;
hDevMode: THandle; 
i, numPaperformats: Integer; 
pPaperFormats: PPapernameArray;
begin
   Printer.PrinterIndex := -1;
   Printer.GetPrinter(Device, Driver, Port, hDevmode);
   numPaperformats := WinSpool.DeviceCapabilities( Device, Port, DC_PAPERNAMES, Nil, Nil );
   If numPaperformats > 0 Then Begin
      GetMem( pPaperformats, numPaperformats * Sizeof( TPapername ));
      try
         WinSpool.DeviceCapabilities( Device, Port, DC_PAPERNAMES, Pchar( pPaperFormats ), Nil);
         sl.Clear;
         For i:= 1 To numPaperformats Do
            sl.add( pPaperformats^[i] );
      finally
         FreeMem( pPaperformats );
      end;
   End;
End;    //設定紙張大小
procedure SetPrinterSize(Const SizeName : String);
var
  _PPrinterInfo2 : PPrinterInfo2;
  pPrinterName : PChar;
  sPrinterName, sFormName : String;
  hPrinter : THandle;
  cbNeeded : DWORD;
  dwBufferSize : DWORD;
begin
  // 設定印表機的紙張大小名稱
  sFormName := SizeName;
  // 取得預設印表機名稱
  sPrinterName := Printer.Printers.Strings[Printer.PrinterIndex];
  if not WinSpool.OpenPrinter(PChar(sPrinterName), hPrinter, nil) then
    raise Exception.Create('OpenPrinter Error, Code : '   IntToStr(GetLastError));
  WinSpool.GetPrinter(hPrinter, 2, nil, 0, @cbNeeded);
  _PPrinterInfo2 := nil;
  try
    GetMem(_PPrinterInfo2, cbNeeded);
    WinSpool.GetPrinter(hPrinter, 2, _PPrinterInfo2, cbNeeded, @cbNeeded);
    with _PPrinterInfo2^.pDevMode^ do
    begin
      StrLCopy(dmFormName, PChar(sFormName), CCHFORMNAME - 1);
      //dmPaperSize := PaperSizeID(sPrinterName, sFormName);
      dmFields := DM_FORMNAME; // DM_PAPERSIZE
    end;
    // 不知為何 SetPrinter 一定會有錯誤 -> GetLastError = ERROR_ACCESS_DENIED
    // (即使以 Administrator 身份執行), 所以先把 raise 註解掉, Who could explain it for me ? Thanks.
    if not WinSpool.SetPrinter(hPrinter, 2, _PPrinterInfo2, 0) then
      ; //raise Exception.Create('SetPrinter Error, Code : '   IntToStr(GetLastError));
  finally
    if _PPrinterInfo2 <> nil then
      FreeMem(_PPrinterInfo2);
    _PPrinterInfo2 := nil;
  end;
end;    procedure TForm1.Button1Click(Sender: TObject);
begin
   GetPapernames(ListBox1.Items);
end;    procedure TForm1.ListBox1Click(Sender: TObject);
begin
   SetPrinterSize(ListBox1.Items.Strings[ListBox1.ItemIndex]);
   QuickRep1.Preview;
end;
至於TPrintSetupDialog...Please forget it kindly~~~ 我不是高手, 高手是正在銀幕前微笑的人.
------


我不是高手, 高手是正在銀幕前微笑的人.
系統時間:2024-04-26 3:44:52
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!