控件的消息处理,一个不难回答的问题!!!!!!!!(50分)

  • 主题发起人 主题发起人 txpaic
  • 开始时间 开始时间
T

txpaic

Unregistered / Unconfirmed
GUEST, unregistred user!
我希望通过消息来处理ComboBox的DropDown事件,于是编写了以下代码<br>TForm1=TForm<br>&nbsp; ....<br>private<br>&nbsp; procedure WmDropDown(var msg:TMessage);message CBN_DROPDOWN;<br>publish<br>.....<br>procedure TForm1.WmDropDown(var msg:TMessage);<br>begin<br>&nbsp;beep;<br>end.<br>但却发现在对ComboBox进行DropDown操作时,没有任何反映。后来我知道这个WmDropDown()<br>函数被TForm1调用后只能响应Form1的操作,所以我希望各位有经验的高手能帮忙解决这个<br>问题--如何让ComboBox能响应自定义的DropDown事件。<br>
 
你把当发生DropDown的事件的程序中写上你自己的过程不就可以了?!如果是事件那么把这个事件的<br>指针也指向你的事件,因为事件也是过程,只是用指针的形式表示罢了,可能我说的不清楚,<br>你再看看有什么人可以和你说清楚的!呵呵
 
unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; StdCtrls;<br><br>type<br>&nbsp; TComboBoxBeep=class(TComboBox)<br>&nbsp; public<br>&nbsp; &nbsp; procedure WmDropDown(var msg:TMessage);message CBN_DROPDOWN;<br>&nbsp; end;<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br>{ TComboBoxBeep }<br><br>procedure TComboBoxBeep.WmDropDown(var msg: TMessage);<br>begin<br>&nbsp; inherited;<br>&nbsp; Beep;<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; A:TComboBoxBeep;<br>begin<br>&nbsp; A:=TComboBoxBeep.Create(self);<br>&nbsp; A.left:=100;<br>&nbsp; A.Top:=100;<br>&nbsp; A.Parent:=Form1;<br>&nbsp; A.Items.Text:='a'+#13#10+'b'+#13#10+'c';<br>end;<br><br>end.<br>
 
要从TComboBox继承一个子类。处理子类的消息
 
wk_knife兄:<br>&nbsp; 你的意思我明白,你希望我执行子类的消息,但是我希望的是执行已经创建好的TComboBox<br>的DropDown的消息事件.有没有好的建议[:)]
 
要这样的话,只能在 application.onMessage 中处理!
 
这样就行:<br>&nbsp; ComboBox1.Perform(CB_SHOWDROPDOWN, 1, 0)<br>
 
后退
顶部