取消固定和关闭取消固定之间的区别

发布于 2024-10-26 10:35:30 字数 1887 浏览 1 评论 0原文

当用户单击固定表单上的“x”时,将调用 OnClose。

当用户在未固定的表单上单击“x”时,将调用 OnHide

当用户在固定的表单上单击“UnPin”时,将调用 OnHide。

我正在尝试将可见表单与菜单系统同步,但我不知道如何确定用户单击“x”和用户单击“UnPin”时 OnHide 事件之间的差异。我想拦截“x”并调用 Close。

带刻度的菜单

每个子项都是 TManagerPanel 的后代,而 TManagerPanel 又是 TForm 的后代,边框样式设置为 bsSizeToolWin,拖动类型设置为 dkDock,拖动模式为 dmAutomatic。

type
    TPanelManager = class(TForm)
    ...
    private
    ...        
        Panels: TManagerPanelList;
        Settings: TSettings; //User Settings
    ...
end;
...

function TPanelManager.InitChild(ChildClass: TManagerPanelClass): TManagerPanel;
var
    Child: TManagerPanel;
begin
    Child := ChildClass.Create(Self);
    Child.Connection := MSConnection1;
    Child.Settings := Settings;
    Child.Styles := Styles;
    ...
    Child.OnPanelClosed := PanelClosed;
    Child.OnPercentChanged := PercentChanged;
    ...
    Child.OnPanelHide := PanelHide;
    Child.Font := Font;
    Child.Initialise;
    Child.ManualDock(DockTarget);
    Panels.AddPanel(Child);
    Result := Child;
end;

procedure TPanelManager.PanelClosed(Sender: TObject; var Action: TCloseAction);
var
    MenuItem: TMenuItem;
    Child: TManagerPanel;
begin
    if Sender is TManagerPanel then
    begin
        Child := TManagerPanel(Sender);
        Action := caFree;
        MenuItem := MenuItemFromChild(Child);
        MenuItem.Checked := False;
        Settings[RemoveAmpersand(MenuItem.Caption)] := MenuItem.Checked;
        Panels.Remove(Child);
    end;
end;

编辑: 我所说的“固定”表单是什么意思:带有固定针的固定表单,使其始终可见。 Pinned

“未固定”表单的含义:释放固定的固定表单,以便选项卡出现在停靠栏中选项卡设置,并且选择选项卡时会出现表单。

取消固定 - 展开

取消固定

Delphi 版本是 2007

When the user clicks 'x' on a Pinned Form OnClose is called.

When the user clicks 'x' on an Unpinned Form OnHide is called

When the user clicks 'UnPin' on a Pinned Form OnHide is called.

I'm trying to synchronise the visible forms with a menu system but I don't know how to determine the difference in the OnHide event between when the user clicks 'x' and when the user clicks 'UnPin'. I want to intercept the 'x' and call Close instead.

Menu with ticks

Each child is a descendant of TManagerPanel which in turn is a descendant of TForm with the border style set to bsSizeToolWin, Drag Kind set to dkDock and Drag Mode is dmAutomatic.

type
    TPanelManager = class(TForm)
    ...
    private
    ...        
        Panels: TManagerPanelList;
        Settings: TSettings; //User Settings
    ...
end;
...

function TPanelManager.InitChild(ChildClass: TManagerPanelClass): TManagerPanel;
var
    Child: TManagerPanel;
begin
    Child := ChildClass.Create(Self);
    Child.Connection := MSConnection1;
    Child.Settings := Settings;
    Child.Styles := Styles;
    ...
    Child.OnPanelClosed := PanelClosed;
    Child.OnPercentChanged := PercentChanged;
    ...
    Child.OnPanelHide := PanelHide;
    Child.Font := Font;
    Child.Initialise;
    Child.ManualDock(DockTarget);
    Panels.AddPanel(Child);
    Result := Child;
end;

procedure TPanelManager.PanelClosed(Sender: TObject; var Action: TCloseAction);
var
    MenuItem: TMenuItem;
    Child: TManagerPanel;
begin
    if Sender is TManagerPanel then
    begin
        Child := TManagerPanel(Sender);
        Action := caFree;
        MenuItem := MenuItemFromChild(Child);
        MenuItem.Checked := False;
        Settings[RemoveAmpersand(MenuItem.Caption)] := MenuItem.Checked;
        Panels.Remove(Child);
    end;
end;

EDIT:
What I mean by a "Pinned" Form: A docked form with the pin set such that it always visible.
Pinned

What I mean by a "UnPinned" Form: A docked form with the pin released such that a tab appears in a dock tab set and the form appears when the tab is selected.

Unpinned - Expanded

Unpinned

Delphi Version is 2007

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

等往事风中吹 2024-11-02 10:35:30

似乎固定和取消固定停靠的表单会更改它在 TTabDockPanel 和我将其停靠到的 TPanel 之间的父级。

将 OnHide 方法添加到演示 Dock 表单...

procedure TfrmDock.FormHide(Sender: TObject);
begin
  if Assigned(Self.Parent) then
      ShowMessage(Self.Parent.ClassName)
  else 
      ShowMessage('No Parent');
end;

现在,当表单隐藏时,我可以区分“浮动”、“停靠、固定”和“停靠、取消固定”。

编辑
我找到了一种更好的方法来做到这一点,

procedure TfrmDock.FormHide(Sender: TObject);
begin
    if Assigned(Parent) then
    begin
        if Not (csDocking in ControlState) then //This was the original test above
        begin
            if Parent is TTabDockPanel then // This is now a safety check
            begin
                if TTabDockPanel(Parent).AnimateSpeed = 1 then //Additional Test
                    //form is closing
                else
                    //form is hiding (Unpinned focused changed)
            end;
        end
        else 
            //form is being unpinned.
    end;
end;

DockCaptionMouseUp中,动画速度设置为1,以便面板看起来关闭(隐藏得非常快)。 “取消固定”也会发生同样的情况,但控制状态会发生变化。

it seems that pinning and unpinning a docked form changes it's parent between a TTabDockPanel and the TPanel I'm docking it to.

Adding an OnHide method to the Demo Dock Form...

procedure TfrmDock.FormHide(Sender: TObject);
begin
  if Assigned(Self.Parent) then
      ShowMessage(Self.Parent.ClassName)
  else 
      ShowMessage('No Parent');
end;

I can now distinguish between "Floating", "Docked,Pinned" and "Docked, Unpinned" when the form gets hidden.

EDIT
I've found a better way of doing this

procedure TfrmDock.FormHide(Sender: TObject);
begin
    if Assigned(Parent) then
    begin
        if Not (csDocking in ControlState) then //This was the original test above
        begin
            if Parent is TTabDockPanel then // This is now a safety check
            begin
                if TTabDockPanel(Parent).AnimateSpeed = 1 then //Additional Test
                    //form is closing
                else
                    //form is hiding (Unpinned focused changed)
            end;
        end
        else 
            //form is being unpinned.
    end;
end;

In DockCaptionMouseUp the Animation Speed is set to 1 so that the panel appears to close (Hides really fast). The same happens for "Unpinning" but control state changes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文