当鼠标停止在某个控件上(50分)

  • 主题发起人 主题发起人 ccdarkness
  • 开始时间 开始时间
C

ccdarkness

Unregistered / Unconfirmed
GUEST, unregistred user!
当鼠标停止在某个控件上怎么相应消息?<br>如:<br>当鼠标划过listbox控件上方,listbox的宽度增加100<br><br>问题是怎么知道鼠标现在在listbox上方?<br>或者怎么实现焦点离开listbox的时候响宽度减少100
 
给你一个例子,希望能够帮助你。。。。<br>如果对于TListBox,可能需要修改类库,或者直接派生。<br>----<br>CM_MOUSEENTER 和 CM_MOUSELEAVE。 &nbsp;Below 已经提供了部分使用它们的代码,<br>我试了,对TSPEEDBUTTON有效,相信对其它也有效。<br>unit SomeForm;<br>interface<br>type<br> &nbsp;TSomeForm = class(TForm)<br> &nbsp; &nbsp;private<br> &nbsp; &nbsp; &nbsp;procedure CMMouseEnter(var Msg: TMessage); message CM_MOUSEENTER;<br> &nbsp; &nbsp; &nbsp;procedure CMMouseLeave(var Msg: TMessage); message CM_MOUSELEAVE;<br> &nbsp;end;<br>implementation<br>procedure TSomeForm.CMMouseEnter(var Msg: TMessage);<br>var<br> &nbsp;anObject : &nbsp; &nbsp; &nbsp; &nbsp;TObject;<br>begin<br> &nbsp;{ anObject is the control over which the mouse is right now }<br><br> &nbsp;anObject := TObject(Msg.lParam);<br> &nbsp;if anObject &nbsp;nil then begin<br> &nbsp; &nbsp;{ First, you must find WHICH is the control under the mouse cursor, }<br> &nbsp; &nbsp;{ then, determine what action to do, etc... }<br> &nbsp;end;<br>end;<br>procedure TSomeForm.CMMouseLeave(var Msg: TMessage);<br>begin<br> &nbsp;{ anObject is the control which the mouse has just gone out of }<br> &nbsp;anObject := TObject(Msg.lParam);<br> &nbsp;if anObject &nbsp;nil then begin<br> &nbsp; &nbsp;{ First, you must find WHICH is the control }<br> &nbsp; &nbsp;{ the mouse cursor has just left, }<br> &nbsp; &nbsp;{ then, determine what action to do, etc... }<br> &nbsp;end;<br>end;<br>end.<br><br>-----------<br>这样改写。。。<br>TForm1<br>TCXListBox=class(TlistBox)<br> &nbsp;public;<br> &nbsp;把刚才上面的改改<br> &nbsp; &nbsp;private<br> &nbsp; &nbsp; &nbsp;procedure CMMouseEnter(var Msg: TMessage); message CM_MOUSEENTER;<br> &nbsp; &nbsp; &nbsp;procedure CMMouseLeave(var Msg: TMessage); message CM_MOUSELEAVE;<br> &nbsp;end;<br>....
 
if anObject &nbsp;nil then begin<br>这句是什么意思?<br><br>&quot;我试了,对TSPEEDBUTTON有效,相信对其它也有效&quot;<br>可否把代码给出
 
private<br> &nbsp; &nbsp;{ Private declarations }<br> &nbsp; &nbsp;//定义两个过程:<br> &nbsp; &nbsp;procedure CMMouseEnter(var Msg: TMessage); message CM_MOUSEENTER;<br> &nbsp; &nbsp;procedure CMMouseLeave(var Msg: TMessage); message CM_MOUSELEAVE;<br><br>procedure TForm1.CMMouseEnter(var Msg: TMessage);<br>var<br> &nbsp;anObject : TObject;<br>begin<br> &nbsp;anObject := TObject(Msg.lParam); &nbsp; &nbsp; &nbsp;<br> &nbsp;//Button1为要感知的组件,可以换为其它组件 &nbsp; &nbsp; &nbsp;<br> &nbsp;if anobject = Button1 then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br> &nbsp; &nbsp;edit1.Text :='Mouse Enter';<br>end;<br><br>procedure TForm1.CMMouseLeave(var Msg: TMessage);<br>var<br> &nbsp;anObject : TObject;<br>begin<br> &nbsp;anObject := TObject(Msg.lParam);<br> &nbsp;if anobject = Button1 then<br> &nbsp; &nbsp;edit1.Text := 'Mouse Leave';<br>end;
 
后退
顶部