【问题标题】:How to fire the OnClick event of a TComboBox when the edit control of the combo box is clicked?单击组合框的编辑控件时如何触发 TComboBox 的 OnClick 事件?
【发布时间】:2018-10-10 07:11:12
【问题描述】:

我有一个带有Style := csDropDown 的 TComboBox。我想这样做,如果用户单击组合框的编辑框部分,则选择该编辑框中的整个文本。所以我想实现组合框的OnClick事件,但是OnClick事件只有在组合框列表显示时才会触发。当列表关闭并且只有一项可见时它不起作用,这是我想要使用它的地方。

我尝试过除OnClick 之外的其他事件,例如OnEnter,但我尝试过的所有事件似乎仅在组合框列表展开时或单击右侧的小箭头时才有效组件。

我也尝试过鼠标事件,比如OnMouseDown,它没有针对组合框发布,但是在设法实现它们之后,它们也只有在鼠标单击小箭头以展开列表时才起作用,或者展开的列表,而不是组合框的编辑框部分。

【问题讨论】:

    标签: delphi


    【解决方案1】:

    这对我有用:

    unit Unit1;
    
    interface
    
    uses
      Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
      Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
    
    type
      TComboBox = class(Vcl.StdCtrls.TComboBox)
      protected
        procedure EditWndProc(var Message: TMessage); override;
      end;
    
      TForm1 = class(TForm)
        ComboBox1: TComboBox;
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    
    { TComboBox }
    
    procedure TComboBox.EditWndProc(var Message: TMessage);
    begin
      inherited;
      if Message.Msg = WM_LBUTTONDOWN then
        SelectAll;
    end;
    
    end.
    

    【讨论】:

      猜你喜欢
      • 2011-10-07
      • 2011-10-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-01
      • 2010-11-25
      相关资源
      最近更新 更多