我试图找出如何在不同的显示器设置下将表单放置在给定的鼠标位置打开。
在表格Error: unexpected '=' in:
"switch(qtr,
1 ="
> 2 = paste(yr, "0104", sep = ""),
Error: unexpected ',' in " 2 = paste(yr, "0104", sep = ""),"
> 3 = paste(yr, "0107", sep = ""),
Error: unexpected ',' in " 3 = paste(yr, "0107", sep = ""),"
> 4 = paste(yr, "0110", sep = ""))
Error: unexpected ')' in " 4 = paste(yr, "0110", sep = ""))"
活动中,我有这个:
centre <- function(x, type) {
switch(type,
mean = mean(x),
median = median(x),
trimmed = mean(x, trim = .1))
}
如果我有2台显示器,并且显示器1设置为主显示器,则表格将在鼠标光标处打开。
但是,如果我将显示器2设置为主显示器,则表单将始终在显示器2上打开。
答案 0 :(得分:5)
如果您只想将表单放在鼠标光标当前所在的同一监视器上,请使用Win32 API MonitorFromPoint()
函数(由VCL的TScreen.MonitorFromPoint()
方法包装),例如:
procedure TSplashScreen.FormCreate(Sender: TObject);
var
r: TRect;
begin
if (Screen.MonitorCount > 1) then
begin
r := Screen.MonitorFromPoint(Mouse.CursorPos).WorkareaRect;
Self.Position := poDesigned;
Self.Left := r.Left + ((r.Width - Width) div 2);
Self.Top := r.Top + ((r.Height - Height) div 2);
{ alternatively:
Self.SetBounds(
r.Left + ((r.Width - Width) div 2),
r.Top + ((r.Height - Height) div 2),
Width, Height);
}
end else begin
Self.Position := poScreenCenter;
end;
end;