工控機介面、數位看板、螢幕保護程式、Kiosk 模式應用程式,需佔據整個螢幕、隱藏標題列與工作列。
procedure TMainForm.FormCreate(Sender: TObject);
begin
with Self do
begin
// 1. 移至螢幕左上角
Top := 0;
Left := 0;
// 2. 移除邊框與標題列
BorderStyle := bsNone;
// 3. 最大化佔滿工作區 (含工作列區域)
WindowState := wsMaximized;
// 4. 強制客戶區大小等於螢幕解析度 (雙重保險)
ClientWidth := Screen.Width;
ClientHeight := Screen.Height;
// 5. 重繪並置頂
Refresh;
SetForegroundWindow(Handle);
SetActiveWindow(Application.Handle);
end;
end;
| 屬性/函式 | 作用 |
|---|---|
| `BorderStyle := bsNone` | 移除標題列、邊框、系統選單、最小化/最大化/關閉鈕 |
| `WindowState := wsMaximized` | 最大化視窗,配合 bsNone 可覆蓋工作列 |
| `ClientWidth/Height := Screen.Width/Height` | 確保客戶區精確符合螢幕解析度 (多螢幕環境下為主螢幕) |
| `SetForegroundWindow(Handle)` | 將視窗帶到 Z-order 最上層並獲得輸入焦點 |
| `SetActiveWindow(Application.Handle)` | 啟動應用程式主視窗 (配合 VCL 訊息迴圈) |
uses MultiMon; // 需在 uses 加入
procedure TMainForm.GoFullScreenOnMonitor(MonitorIndex: Integer);
var
Mon: HMONITOR;
MI: TMonitorInfo;
begin
Mon := Screen.Monitors[MonitorIndex].Handle;
MI.cbSize := SizeOf(TMonitorInfo);
GetMonitorInfo(Mon, @MI);
// 使用工作區 (排除工作列) 或整個監視器區域
BoundsRect := MI.rcMonitor; // 整個螢幕
// BoundsRect := MI.rcWork; // 排除工作列
end;
Delphi 實現全螢幕無標題列視窗的核心組合:**`BorderStyle := bsNone` + `WindowState := wsMaximized` + `ClientWidth/Height := Screen.Width/Height`**。搭配 `SetForegroundWindow` 置頂與退出熱鍵,即可構建專業的 Kiosk/工控介面。