请问怎么实现在combobox中键盘输入无效,除tab,回车等功能键外?小弟正在练习做个简单的控件(只读combobox)如果哪为能提供源代码50分酬谢

解决方案 »

  1.   

    在combobox的OnKeyPress事件中
    procedure TForm1.ComboBox1KeyPress(Sender: TObject; var Key: Char);
    begin
      if not (Key in [#8,#9,#13]) then Key := #0;
    end;
      

  2.   

    to: sysu(死树) 
    我的意思不是说要在程序中实现,而是要在自定义控件代码中实现,好象要通过截取键盘消息,用钩子函数类的,小弟对这些不太懂,特请教
      

  3.   

    unit ComboBox1;interfaceuses
      Windows, Messages, SysUtils, Classes, Controls, StdCtrls;type
      TComboBox1 = class(TComboBox)
      private
        { Private declarations }
        FReadOnly: Boolean;
        procedure SetReadOnly(Value: Boolean);
      protected
        { Protected declarations }
        procedure CreateWnd; override;
      public
        { Public declarations }
      published
        { Published declarations }
        property ReadOnly: Boolean read FReadOnly write SetReadOnly default False;
      end;procedure Register;implementationprocedure TComboBox1.CreateWnd;
    begin
      inherited CreateWnd;
      if FEditHandle <> 0 then
        SendMessage(FEditHandle, EM_SETREADONLY, Ord(FReadOnly), 0);
    end;procedure TComboBox1.SetReadOnly(Value: Boolean);
    begin
      if FReadOnly <> Value then
      begin
        FReadOnly := Value;
        if FEditHandle <> 0 then
          SendMessage(FEditHandle, EM_SETREADONLY, Ord(Value), 0);
      end;
    end;procedure Register;
    begin
      RegisterComponents('Samples', [TComboBox1]);
    end;end.