用delphi寫多屏幕程序

別現在有些POS機是雙屏幕的(比如卡西瓦POS機),一個屏幕可以當顧客顯示屏用,當閒時也可以顯示一些廣告。其實用delphi寫雙屏幕的程序是比較簡單的,Screen.MonitorCount就是當前系統屏幕的數量,TForm也有與屏幕相關的屬性,比如DefaluMonitor,不過想設一個窗體顯示在哪個屏幕上好象沒有屬性(可能我沒找到),不過研究VCL代碼發現如何把一個窗體顯示在某個屏幕上(可以看TCustomForm的SetWindowToMonitor方法),把它抽出來封裝成一個函數:

//Form:目標窗體 monitorIndex:顯示在哪個屏幕 0爲當前屏幕,1爲第2個屏幕.....

procedure SetFormMonitor(Form:TCustomForm;MonitorIndex:integer);
begin
if (MonitorIndex>-1) and (MonitorIndex<Screen.MonitorCount) then//保證屏幕索引在範圍內
begin
    Form.SetBounds(Screen.Monitors[MonitorIndex].Left + ((Screen.Monitors[MonitorIndex].Width - Form.Width) div 2),
      Screen.Monitors[MonitorIndex].Top + ((Screen.Monitors[MonitorIndex].Height - Form.Height) div 2),
       Form.Width, Form.Height);
end;
end;

之後要顯示哪個窗體在哪個屏幕調一下函數就可以了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章