Control's OnExit eats up mouseup event for new control when showing another window

前端 未结 3 1160
小鲜肉
小鲜肉 2020-12-12 04:08

I found this question on Experts-Exchange.

Control\'s OnExit eats up mouseup event for new control when showing another window

The probl

3条回答
  •  北海茫月
    2020-12-12 04:47

    Once again PostMessage to the rescue! Defer your dialog just a little bit longer so that Windows can finish its focus change. Post yourself a message instead of showing the dialog directly:

    const
      WM_SHOWMYDIALOG = WM_APP + 321;
    
    TForm1 = class(TForm)
      Edit1: TEdit;
      Edit2: TEdit;
      procedure Edit1Exit(Sender: TObject);
    private
      procedure WMSHOWMYDIALOG(var Message: TMessage); message WM_SHOWMYDIALOG;
    end;
    
    procedure TForm1.Edit1Exit(Sender: TObject);
    begin
      PostMessage(Self.Handle, WM_SHOWMYDIALOG, 0, 0);
    end;
    
    procedure TForm1.WMSHOWMYDIALOG(var Message: TMessage);
    begin
      ShowMessage('Nice one');
    end;
    

    And everything is fine :)

提交回复
热议问题