如何判断鼠标在指定窗体里按下鼠标左键?在线等!!(100分)

  • 主题发起人 夫罗多
  • 开始时间

夫罗多

Unregistered / Unconfirmed
GUEST, unregistred user!
指定窗体里的按钮没有HANDLE,只知道它所在的坐标范围,如何得到在指定位置按下鼠标的信息呢?本人新手,请贴代码,谢谢!<br><br>就是这样的代码(比如5没有HANDLE 只能通过区域来判断)监视鼠标在计算器上&quot;5&quot;的位置按下左键 的程序代码 &nbsp;只要在5的位置按下左键就ShowMessage()
 
用鼠标单击事件试试,然后,判断范围。代码。希望还是你自己解决,我也很懒的。呵呵
 
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;<br> &nbsp;Shift: TShiftState; X, Y: Integer);<br>var<br> &nbsp;rRect: TRect;<br>begin<br> &nbsp;rRect := &nbsp;Rect(10, 10, 100, 100);<br> &nbsp;if (X &gt; rRect.Left) and (X &lt; rRect.Right)<br> &nbsp; &nbsp;and (Y &gt; rRect.Top) and ( Y &lt; rRect.Bottom) then<br> &nbsp;begin<br> &nbsp; &nbsp;ShowMessage('Ok');<br> &nbsp;end;<br>end;<br>本来想对代码解释一下,看了一下,真看不出为什么腰写出这些代码!<br><br>唉,DFW的未来在哪里?
 
rRect := Form.Rect;<br> &nbsp;if (X &gt; rRect.Left) and (X &lt; rRect.Right)<br> &nbsp; &nbsp;and (Y &gt; rRect.Top) and ( Y &lt; rRect.Bottom) then<br> &nbsp;begin<br> &nbsp; &nbsp;ShowMessage('Ok');<br> &nbsp;end;
 
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;<br> &nbsp;Shift: TShiftState; X, Y: Integer);<br>begin<br> &nbsp;if Button=left &nbsp;begin<br> &nbsp; &nbsp;ShowMessage('left btn press');<br> &nbsp;end;<br>end;
 
//改一下楼上的:)<br>procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;<br> &nbsp;Shift: TShiftState; X, Y: Integer);<br>begin<br> &nbsp;if Button = mbLeft then<br> &nbsp; &nbsp;ShowMessage('mouse left btn press');<br>end;
 
哈哈,你个臭小子
 
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;<br> &nbsp;Shift: TShiftState; X, Y: Integer);<br>var<br> &nbsp;rRect: TRect;<br>begin<br> &nbsp;rRect := &nbsp;Rect(10, 10, 100, 100); //里面的四个参数,前两个是窗体(注意不是屏幕)的左上角的x,y后两个是右下角的x,y;你可以自己定区域的<br> &nbsp;if (X &gt; rRect.Left) and (X &lt; rRect.Right)<br> &nbsp; &nbsp;and (Y &gt; rRect.Top) and ( Y &lt; rRect.Bottom) then<br> &nbsp;begin<br> &nbsp; &nbsp;ShowMessage('Ok');<br> &nbsp;end;<br>end;
 
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;<br> &nbsp;Shift: TShiftState; X, Y: Integer);<br>begin<br> &nbsp;if Button = mbLeft then<br> &nbsp; &nbsp;ShowMessage('mouse left button pressed');<br>end;
 
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;<br> &nbsp;Shift: TShiftState; X, Y: Integer);<br>begin<br> &nbsp;if Button=left &nbsp;begin<br> &nbsp; &nbsp;ShowMessage('left btn press');<br> &nbsp;end;<br>end;
 
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;<br> &nbsp;Shift: TShiftState; X, Y: Integer);<br>begin<br> &nbsp;if Button = mbLeft then<br> &nbsp; &nbsp;ShowMessage('左键');<br> &nbsp;if Button = mbRight then<br> &nbsp; &nbsp;ShowMessage('右键');<br>end;
 
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;<br> &nbsp;Shift: TShiftState; X, Y: Integer);<br>begin<br> &nbsp;if Button = mbLeft then<br> &nbsp; &nbsp;ShowMessage('Left');<br> &nbsp;if Button = mbRight then<br> &nbsp; &nbsp;ShowMessage('Right');<br>end;
 
已经回答你了啊
 

Similar threads

回复
0
查看
658
不得闲
S
回复
0
查看
625
SUNSTONE的Delphi笔记
S
S
回复
0
查看
706
SUNSTONE的Delphi笔记
S
S
回复
0
查看
956
SUNSTONE的Delphi笔记
S
顶部