【问题标题】:How to Pop-up Form on Right Click?如何右键弹出表单?
【发布时间】:2011-11-22 13:01:38
【问题描述】:

当我右键单击 TPaintBox 时,我需要能够弹出一个 TForm(表单的内容将取决于我单击的位置)。如果用户单击其他任何地方,我希望原始表单被销毁(或至少消失)。如果新的单击恰好是在 TPaintBox 上的另一个右键单击,则必须出现一个新的 TForm。基本上,它是一种右键属性查询类型的操作,即右键单击以获取 TPaintBox 区域的属性。

这似乎比我想象的要困难。当使用 OnDeactivate 事件停用弹出窗口时,我首先尝试销毁弹出表单。这导致弹出窗口未显示。

【问题讨论】:

    标签: delphi


    【解决方案1】:

    这是我的解决方案(经过测试且有效)...

    type
      TForm1 = class(TForm)
        ...
      private
        ContextForm: TfrmContext;
      end;
    
    ...
    
    implementation
    
    procedure TForm1.Button1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    begin
      if ContextForm <> nil then
        FreeAndNil(ContextForm);
     if Button = mbRight then
      begin
        ContextForm := TfrmContext.Create(Application);
        ContextForm.SetParentComponent(Application);
        ContextForm.Left := Mouse.CursorPos.X;
        ContextForm.Top := Mouse.CursorPos.Y;
        ContextForm.Show;
      end;
    end;
    
    procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    begin
      if ContextForm <> nil then
        FreeAndNil(ContextForm);
    end;
    

    在此演示中,右键单击 Button1 将创建您的“上下文表单”(这是一个 TForm)并设置它的位置,以便“上下文表单”的左上角正好位于鼠标光标所在的位置。

    单击表单上的其他任何位置都会破坏上下文表单。

    享受吧!

    【讨论】:

    • 很遗憾史蒂夫“问了就跑了”(当然他的统计数据会表明这一点)意味着这个问题可能永远不会被标记为已回答(即使它是):(
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多