比如,现在焦点在Button1上,我在Button2上单击鼠标右键,怎么使Button2获得焦点呢?

解决方案 »

  1.   

    在Button2的OnMouseDown事件中:
    procedure TForm1.Button2MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
      if Button = mbRight then Button2.SetFocus;
    end;
      

  2.   

    如果想所有控件按右键时都获得焦点,则把控件的OnMouseDown事件都指向Button2,然后改为:
    procedure TForm1.Button2MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
      if Button = mbRight then (Sender as TWinControl).SetFocus;
    end;