2011-10-19 112 views

回答

7

這裏主要的複雜因素是多個顯示器。使用多臺顯示器時,桌面上可能沒有頂點和右側。在這種情況下,我認爲你的意思可能是最右邊顯示器的頂部。

做這樣的:

procedure MoveFormToTopOfRightmostMonitor(Form: TForm); 
var 
    i: Integer; 
    Monitor, RightMostMonitor: TMonitor; 
begin 
    RightMostMonitor := Screen.Monitors[0]; 
    for i := 1 to Screen.MonitorCount-1 do 
    begin 
    Monitor := Screen.Monitors[i]; 
    if Monitor.Left+Monitor.Width > RightMostMonitor.Left+RightMostMonitor.Width then 
     Monitor := RightMostMonitor; 
    end; 
    Form.Left := Monitor.Left+Monitor.Width-Form.Left; 
    Form.Top := Monitor.Top; 
end; 
+0

@rakesh我只是固定在代碼中的錯誤。我錯誤地設置了「Form.Top」。使用您現在看到的版本。 –

+0

@rakesh如果這是你的問題的答案,請記住接受它。最近你似乎忘記了這一步。 –

0

試試這個

procedure TmainForm.FormCreate(Sender: TObject); 
begin 
mainForm.left:= screen.Monitors[Screen.MonitorCount-1].Width-mainForm.Width; 
end;