listbox中onclick事件如何区分是方向键引发的,还是鼠标左键引发的呢? ( 积分: 50 )

  • 主题发起人 主题发起人 yjingz
  • 开始时间 开始时间
Y

yjingz

Unregistered / Unconfirmed
GUEST, unregistred user!
listbox1中使用方向键移动光标时,在触发onkeydown,onkeyup后还会触发一次listbox1的onclick事件.<br>这样看来listbox1的onclick可以使用鼠标键直接触发,也可以由方向键触发,<br>我现在想问的是,如何在listbox1的onclick事件中判断这两种情况:<br>如:<br>procedure Form1.listbox1click(sender:Tobject);<br>begin<br> &nbsp;if {是方向键触发的} then showmessage('方向键触发');<br> &nbsp;if {是鼠标触发的} then showmessage('鼠标触发');<br>end;
 
listbox1中使用方向键移动光标时,在触发onkeydown,onkeyup后还会触发一次listbox1的onclick事件.<br>这样看来listbox1的onclick可以使用鼠标键直接触发,也可以由方向键触发,<br>我现在想问的是,如何在listbox1的onclick事件中判断这两种情况:<br>如:<br>procedure Form1.listbox1click(sender:Tobject);<br>begin<br> &nbsp;if {是方向键触发的} then showmessage('方向键触发');<br> &nbsp;if {是鼠标触发的} then showmessage('鼠标触发');<br>end;
 
帮顶<br> <br> --------签名档---------------------------<br> <br> 惊爆开源站<br> <br> http://www.source520.com <br><br> 80G源码电子书免费免注册下载,大量精辟技术文档库随时更新
 
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;TClickFlag = (cfNone,cfMouse,cfBroad);<br>type<br> &nbsp;TForm1 = class(TForm)<br> &nbsp; &nbsp;ListBox1: TListBox;<br> &nbsp; &nbsp;procedure ListBox1Click(Sender: TObject);<br> &nbsp; &nbsp;procedure ListBox1KeyDown(Sender: TObject; var Key: Word;<br> &nbsp; &nbsp; &nbsp;Shift: TShiftState);<br> &nbsp; &nbsp;procedure ListBox1MouseDown(Sender: TObject; Button: TMouseButton;<br> &nbsp; &nbsp; &nbsp;Shift: TShiftState; X, Y: Integer);<br> &nbsp;private<br> &nbsp; &nbsp;{ Private declarations }<br> &nbsp; &nbsp;FClickFlag : TClickFlag;<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>procedure TForm1.ListBox1Click(Sender: TObject);<br>begin<br> &nbsp;Case FClickFlag of<br> &nbsp; &nbsp;cfMouse : showmessage('鼠标触发');<br> &nbsp; &nbsp;cfBroad : showmessage('方向键触发');<br> &nbsp; &nbsp;else &nbsp;showmessage('未知');<br> &nbsp;end;<br>end;<br><br>procedure TForm1.ListBox1KeyDown(Sender: TObject; var Key: Word;<br> &nbsp;Shift: TShiftState);<br>begin<br> &nbsp;if Key in [vk_up,vk_left,vk_right,vk_down] then<br> &nbsp; &nbsp;FClickFlag := cfBroad;<br>end;<br><br>procedure TForm1.ListBox1MouseDown(Sender: TObject; Button: TMouseButton;<br> &nbsp;Shift: TShiftState; X, Y: Integer);<br>begin<br> &nbsp;FClickFlag := cfMouse;<br>end;
 
接受答案了.
 
后退
顶部