100分,求一个简便有效的鼠标单击和双击事件的判断方法(100分)

  • 主题发起人 主题发起人 fangyi
  • 开始时间 开始时间
F

fangyi

Unregistered / Unconfirmed
GUEST, unregistred user!
最好有代码。<br>这不算复杂的问题吧?<br>我属于初学者,但诚心请教,请不要嘲笑我,ok?<br><br><br>
 
好像有click和dbclick事件吧?
 
不是,我的意思是加上判断<br>比如:<br>procedure TForm1.FormClick(Sender: TObject);<br>begin<br>showmessage('click');<br>end;<br><br>procedure TForm1.FormDblClick(Sender: TObject);<br>begin<br>showmessage('dblclick');<br>end;<br><br>这样子一定是不成的,因为,form响应了click之后就不理睬dblclick了。<br>肯定是需要判断的,但是我不太明白怎么加,加在哪里比较合适。
 
你试过吗?真的不行?
 
当然,你可以试试看 &nbsp;:)<br>
 
form在响应click和dblclick是不一样的,OS定义了在设定的时间间隔内连续两次<br>鼠标单击作为dblclick处理,不再触发click事件
 
在FormMouseDown/up中写代码啊。很简单的,为什么不动脑子?<br>if ssDouble in ssshift then<br>&nbsp; ///双击<br>else<br>&nbsp; ///单击
 
sorry,你给的答案我不是很明白,而且代码有问题<br>好像需要把ssDouble in ssshift 改成ssDouble in shift 才可以通过的,不是我需要的<br>效果呀。<br>你可以解释的详细一点吗?我不是想解决了问题就搞定的,我想知道这种类似问题的解决<br>办法的思路
 
哎,这个shift就表明了鼠标的状态啊。你难道不会看看TShiftState这个集合的帮助么?
 
上面的就可以了.
 
用鼠标在控件上点击一下,单击事件总是会发生,实际上,每次双击鼠标时会先<br>触发一次单击事件,然后触发一次双击事件,如果你用showmessage显示信息,那<br>就会阻止双击事件的发生(因为,显示的对话框是模式的,程序出于等待状态),<br>你可以看下面这个例子:<br>var<br>&nbsp; Form1: TForm1;<br>&nbsp; i: Integer = 1;<br><br>implementation<br><br>{$R *.dfm}<br><br>procedure TForm1.FormClick(Sender: TObject);<br>begin<br>&nbsp; caption := '单击';<br>&nbsp; Inc(i);<br>&nbsp; label1.Caption := IntToStr(i);<br>end;<br><br>procedure TForm1.FormDblClick(Sender: TObject);<br>begin<br>&nbsp; caption := '双击';<br>&nbsp; Inc(i);<br>&nbsp; label1.Caption := IntToStr(i);<br>end;<br>-------------<br>如果在窗口上单击鼠标,你会看到窗口的标题变成了“单击”,label1的显示计数加一;<br>如果双击,则标题变为“双击”,计数器会加二(单击事件加了一次,双击事件加了一次)。<br>所以,只要程序不使用模式窗口之类的东西,程序还是会触发双击事件的。
 
feifeich, 谢谢,但是按照这样的处理办法的话没有办法解决我的问题<br>比如:单击windows右下角音量的trayicon 会出来一个小的调节版<br>&nbsp; &nbsp; &nbsp; 双节它会出来一个详细的窗口<br>类似的应用有很多。我就是要实现这种功能<br><br>但是你的简单例子让我明白了一些东西,先给你加上50分可以吗?我的分不多 &nbsp;:)<br><br>再次感谢!
 
老兄csdn中也有这样的问题<br>你看看下面的方法 ( 记得一定要给分噢! )<br><br>一、<br>mousedown事件里面有一参数button吧。<br>当button = 1的时候是左键<br>&nbsp; button = 2的时候是右键<br>&nbsp; button = 3的时候是双键<br>&nbsp; button = 4的时候是中间的键<br>连机的话,你可以把SERVER和CLINET结合放到一起。<br>这样看上去就是点对点连接了。<br><br>二、<br>Virtual Key Code Corresponding key<br>————————————————————————<br>VK_LBUTTON Left mouse button<br>VK_RBUTTON Right mouse button<br>VK_MBUTTON Middle mouse button<br><br>这个是DELPHI中自定义的按键值 老兄 你看看也很有用的(特意去找的 你可要给我分哦)<br>
 
VK_LBUTTON Left mouse button<br>VK_RBUTTON Right mouse button<br>VK_CANCEL Control+Break<br>VK_MBUTTON Middle mouse button<br>VK_BACK Backspace key<br>VK_TAB Tab key<br>VK_CLEAR Clear key<br>VK_RETURN Enter key<br>VK_SHIFT Shift key<br>VK_CONTROL Ctrl key<br>VK_MENU Alt key<br>VK_PAUSE Pause key<br>VK_CAPITAL Caps Lock key<br>VK_KANA Used with IME<br>VK_HANGUL Used with IME<br>VK_JUNJA Used with IME<br>VK_FINAL Used with IME<br>VK_HANJA Used with IME<br>VK_KANJI Used with IME<br>VK_CONVERT Used with IME<br><br>VK_NONCONVERT Used with IME<br>VK_ACCEPT Used with IME<br>VK_MODECHANGE Used with IME<br>VK_ESCAPE Esc key<br>VK_SPACE Space bar<br>VK_PRIOR Page Up key<br>VK_NEXT Page Down key<br>VK_END End key<br>VK_HOME Home key<br>VK_LEFT Left Arrow key<br>VK_UP Up Arrow key<br>VK_RIGHT Right Arrow key<br>VK_DOWN Down Arrow key<br>VK_SELECT Select key<br>VK_PRINT Print key (keyboard-specific)<br>VK_EXECUTE Execute key<br>VK_SNAPSHOT Print Screen key<br>VK_INSERT Insert key<br>VK_DELETE Delete key<br>VK_HELP Help key<br><br>VK_LWIN Left Windows key (Microsoft keyboard)<br>VK_RWIN Right Windows key (Microsoft keyboard)<br>VK_APPS Applications key (Microsoft keyboard)<br>VK_NUMPAD0 0 key (numeric keypad)<br>VK_NUMPAD1 1 key (numeric keypad)<br>VK_NUMPAD2 2 key (numeric keypad)<br>VK_NUMPAD3 3 key (numeric keypad)<br>VK_NUMPAD4 4 key (numeric keypad)<br>VK_NUMPAD5 5 key (numeric keypad)<br>VK_NUMPAD6 6 key (numeric keypad)<br>VK_NUMPAD7 7 key (numeric keypad)<br>VK_NUMPAD8 8 key (numeric keypad)<br>VK_NUMPAD9 9 key (numeric keypad)<br><br>VK_MULTIPLY Multiply key (numeric keypad)<br>VK_ADD Add key (numeric keypad)<br>VK_SEPARATOR Separator key (numeric keypad)<br>VK_SUBTRACT Subtract key (numeric keypad)<br>VK_DECIMAL Decimal key (numeric keypad)<br>VK_DIVIDE Divide key (numeric keypad)<br>VK_F1 F1 key<br>VK_F2 F2 key<br>VK_F3 F3 key<br>VK_F4 F4 key<br>VK_F5 F5 key<br>VK_F6 F6 key<br>VK_F7 F7 key<br>VK_F8 F8 key<br>VK_F9 F9 key<br>VK_F10 F10 key<br>VK_F11 F11 key<br>VK_F12 F12 key<br>VK_F13 F13 key<br>VK_F14 F14 key<br>VK_F15 F15 key<br><br>VK_F16 F16 key<br>VK_F17 F17 key<br>VK_F18 F18 key<br>VK_F19 F19 key<br>VK_F20 F20 key<br>VK_F21 F21 key<br>VK_F22 F22 key<br>VK_F23 F23 key<br>VK_F24 F24 key<br>VK_NUMLOCK Num Lock key<br>VK_SCROLL Scroll Lock key<br>VK_LSHIFT Left Shift key (only used with GetAsyncKeyState and GetKeyState)<br>VK_RSHIFT Right Shift key &nbsp;(only used with GetAsyncKeyState and GetKeyState)<br>VK_LCONTROL Left Ctrl key &nbsp;(only used with GetAsyncKeyState and GetKeyState)<br>VK_RCONTROL Right Ctrl key &nbsp;(only used with GetAsyncKeyState and GetKeyState)<br><br>VK_LMENU Left Alt key &nbsp;(only used with GetAsyncKeyState and GetKeyState)<br>VK_RMENU Right Alt key &nbsp;(only used with GetAsyncKeyState and GetKeyState)<br>VK_PROCESSKEY Process key<br>VK_ATTN Attn key<br>VK_CRSEL CrSel key<br>VK_EXSEL ExSel key<br>VK_EREOF Erase EOF key<br>VK_PLAY Play key<br>VK_ZOOM Zoom key<br>VK_NONAME Reserved for future use<br>VK_PA1 PA1 key<br>VK_OEM_CLEAR Clear key<br><br>在delphi 中就有啊
 
我还需要去试试看你的方法,找到解决办法了一定给分的
 
&nbsp; WM_LBUTTONDOWN &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //按下鼠标左键<br>&nbsp; WM_LBUTTONUP &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//释放鼠标左键<br>&nbsp; WM_LBUTTONDBLCLK &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//双击鼠标左键<br>&nbsp; WM_RBUTTONDOWN &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//按下鼠标右键<br>&nbsp; WM_RBUTTONUP &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //释放鼠标右键<br>&nbsp; WM_RBUTTONDBLCLK &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//双击鼠标右键<br>&nbsp; WM_MBUTTONDOWN &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//按下鼠标中键 <br>&nbsp; WM_MBUTTONUP &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//释放鼠标中键<br>&nbsp; WM_MBUTTONDBLCLK &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//双击鼠标中键<br>&nbsp; 截获其中的某个消息处理就行了 &nbsp;
 
楼上的,可以
 
也许可以重新实现控件对于消息的处理函数。<br>
 
其实很多时候都有简单的解决方法,看上去不起眼,实际效果却不错。<br>你用鼠标点击windows的音量图标,细心的你也许已经发现,当你双击<br>它时很快就弹出了音量控制窗口,而单击时却要等一小会才会出现音量<br>调节杆,如果你用过MSN,它也是这样的。这不正提醒我们,它在单击之后<br>并没有马上执行,而是调用了一个延时过程。于是我这么实现你的要求:<br>使用timer组件,单击后激活它,双击关闭它,timer事件执行完也关闭自己。<br>下面是简单代码(应该不用贴出来的吧:)<br>我把timer的间隔设为500(半秒)了,你可以更加需要调节的吧。<br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Timer1: TTimer;<br>&nbsp; &nbsp; procedure Timer1Timer(Sender: TObject);<br>&nbsp; &nbsp; procedure FormClick(Sender: TObject);<br>&nbsp; &nbsp; procedure FormDblClick(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>procedure TForm1.Timer1Timer(Sender: TObject);<br>begin<br>&nbsp; timer1.Enabled := false;<br>&nbsp; showmessage('单击');<br>end;<br><br>procedure TForm1.FormClick(Sender: TObject);<br>begin<br>&nbsp; timer1.Enabled := false;<br>&nbsp; timer1.Enabled := true;<br>end;<br><br>procedure TForm1.FormDblClick(Sender: TObject);<br>begin<br>&nbsp; timer1.Enabled := false;<br>&nbsp; showmessage('双击');<br>end;<br><br>end.
 
feifeich,给分啦!!<br>非常感谢,就是这个结果。道理我也明白了。<br>至于其它的众位高手,你们的帮助我不会忘记的,只是,我的分数不多了,我又是初学<br>delphi很难在这里挣分啦,吝啬一点请原谅! &nbsp; :)
 
后退
顶部