在onresize里面写form1.postion:=poScreenCenter;报错?
出现 'can't change visible in OnShow and Onhide ‘错误!
写在Oncreate里面肯定是可以的,但为什么写onresize里面不行?
form1.width和form1.heght都可以控制,form1.postion:=poScreenCenter;却报错?
出现 'can't change visible in OnShow and Onhide ‘错误!
写在Oncreate里面肯定是可以的,但为什么写onresize里面不行?
form1.width和form1.heght都可以控制,form1.postion:=poScreenCenter;却报错?
 ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄
procedure TForm1.FormShow(Sender: TObject);
begin
Form1.Hide;
end;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
在显示窗口时,隐藏窗口
经验只谈啊我以前也用过类似的语句,后来总是出错,就改为设置Self.Left的模式了
具体在Onresize事件和form1.positon:=poScreenCenter是怎么个矛盾了?我的确不知道矛盾出在哪里?
OnResize 就是重新给窗体和控件布局,但这句代码也是重新给窗体布局,也没什么冲突啊?
var
AppMon, WinMon: HMONITOR;
I, J: Integer;
ALeft, ATop: Integer;
LRect: TRect;
begin
if (FDefaultMonitor <> dmDesktop) and (Application.MainForm <> nil) then
begin
AppMon := 0;
if FDefaultMonitor = dmMainForm then
AppMon := Application.MainForm.Monitor.Handle
else if (FDefaultMonitor = dmActiveForm) and (Screen.ActiveCustomForm <> nil) then
AppMon := Screen.ActiveCustomForm.Monitor.Handle
else if FDefaultMonitor = dmPrimary then
AppMon := Screen.PrimaryMonitor.Handle;
WinMon := Monitor.Handle;
for I := 0 to Screen.MonitorCount - 1 do
if (Screen.Monitors[I].Handle = AppMon) then
if (AppMon <> WinMon) then
begin
for J := 0 to Screen.MonitorCount - 1 do
begin
if (Screen.Monitors[J].Handle = WinMon) then
begin
if FPosition = poScreenCenter then
begin
LRect := Screen.Monitors[I].WorkareaRect;
SetBounds(LRect.Left + ((RectWidth(LRect) - Width) div 2),
LRect.Top + ((RectHeight(LRect) - Height) div 2), Width, Height);
end
else
if FPosition = poMainFormCenter then
begin
SetBounds(Screen.Monitors[I].Left + ((Screen.Monitors[I].Width - Width) div 2),
Screen.Monitors[I].Top + ((Screen.Monitors[I].Height - Height) div 2),
Width, Height)
end
else
begin
ALeft := Screen.Monitors[I].Left + Left - Screen.Monitors[J].Left;
if ALeft + Width > Screen.Monitors[I].Left + Screen.Monitors[I].Width then
ALeft := Screen.Monitors[I].Left + Screen.Monitors[I].Width - Width;
ATop := Screen.Monitors[I].Top + Top - Screen.Monitors[J].Top;
if ATop + Height > Screen.Monitors[I].Top + Screen.Monitors[I].Height then
ATop := Screen.Monitors[I].Top + Screen.Monitors[I].Height - Height;
SetBounds(ALeft, ATop, Width, Height);
end;
end;
end;
end
else
begin
if FPosition = poScreenCenter then
begin
LRect := Screen.Monitors[I].WorkareaRect;
SetBounds(LRect.Left + ((RectWidth(LRect) - Width) div 2),
LRect.Top + ((RectHeight(LRect) - Height) div 2), Width, Height);
end;
end;
end;
end;
还是没看出什么门道?给指点指点,
小弟在此谢过了!
触发Oncreate时,窗体的一些初始化信息都已经准备好了,当然包括窗体大小位置信息只是没显示出来, 即hide。
接着触发onshow事件,如果此时:form1.postion:=poScreenCenter或者form.visible:=false都会出现上述错误,也就是说form1.postion执行此句时操作了visible,具体上面没有看出操作visible的代码啊?
...
if FPosition = poScreenCenter then SetBounds(...)因为 form1.postion:=poScreenCenter 会改变 form1 的尺寸和位置,在 onResize 中
执行到 form1.postion:=poScreenCenter 时会重新激活 onResize 事件,造成死循环。