我在TStringGrid中动态生成了TComboBox,作为TStringGrid中的cell的输入。当输入完成,必须隐藏或销毁该TComboBox。我的想法是当mouse点击该TCombo以外的地方时,认为输入结束,然后隐藏或销毁该TComboBox。问题是当mouse点击TStringGrid内部时,能获得mouse已离开TComboBox的通知,但当mouse点击TStringGrid外部时,无法得到。怎么办?

解决方案 »

  1.   

    procedure TForm1.ComboBox1Exit(Sender: TObject);
    begin
      showmessage('a');
    end;
      

  2.   

    我想可以利用MouseDown事件,当mouse点击TStringGrid外部时判断mouse的坐标,这样来取代TCombobox的OnExit事件。
    我菜,就想到这办法。
      

  3.   

    根据楼主的意思,当在TComboBox外点击时,肯定焦点是从TComboBox转移出来,所以一楼的方法可以,直接在OnExit中进行!不过我认为楼主的这种处理方式不是正规方式,比较正规的方式应该是操纵TStringGrid的TInplaceEdit对象!
      

  4.   

    当mouse点击TStringGrid外部时,如果焦点没有落在其他控件上,那么焦点还是停留在TCombobox上,所以并没有触发TCombobox的OnExit事件啊,我想楼主遇到的正是这种情况
      

  5.   

    确实,当mouse点击TStringGrid外部时,焦点还是停留在TCombobox上,并没有触发TCombobox的OnExit事件。TStringGrid外部包括20多个菜单项,10多个工具按钮,还有其它控件,它对OnMouseDown事件都是忽略的,我想可能是这个原因没有触发TCombobox的OnExit事件。除了响应每个控件的OnMouseDown事件外,还有别的方法吗?
    to FrameSniper(§绕瀑游龙§):使用TStringGrid的TInplaceEdit对象的方法能说的详细一些吗?
      

  6.   

    to cmain83(龙行天下2008)
    能说明白些吗?
      

  7.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, Menus;type
      TForm1 = class(TForm)
        ComboBox1: TComboBox;
        MainMenu1: TMainMenu;
        fdasfdsaf1: TMenuItem;
        fdsafdsa1: TMenuItem;
        dfasf1: TMenuItem;
        fdasf1: TMenuItem;
        dfsafda1: TMenuItem;
        Button1: TButton;
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
         procedure ApplicationMessage(var Msg: tagMSG; var Handled: Boolean);
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}{ TForm1 }procedure TForm1.ApplicationMessage(var Msg: tagMSG; var Handled: Boolean);
    begin
      if NOT (IsChild(Self.ComboBox1.Handle, Msg.Hwnd)) and ((Msg.Message = WM_LBUTTONDOWN)
         or (Msg.Message = WM_RBUTTONDOWN ))then
      begin
        //在此处加上你的处理语句
        inherited;
      end;
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
      Application.OnMessage := Self.ApplicationMessage;
    end;end.