Click here to Skip to main content
15,917,793 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to execute the code written in button 1 click event whilst button 1 is pressed.
When I release the button then execution should stop.

Please give me by which property or method of textbox I can perform this.

Thank you.
Posted
Updated 16-May-11 21:27pm
v2
Comments
Sergey Alexandrovich Kryukov 17-May-11 3:05am    
Tag it! WPF, Forms, ASP.NET, what?!
--SA
Dalek Dave 17-May-11 3:28am    
Edited for Grammar, Syntax and Readability.

Anand,

You want to execute code written in button_Click. Do you want to call an Asynchronous call or Synchronous call, once you execute button_Click method then it return after executing Click method.

If you don't want to execute them then you should use button_MouseUp method instead, MouseUp only executes when button released.

You should also attach same Event to KeyUp as it may possible that user use keyboard to click button not mouse.

I hope you clear your doubt, if not please describe us what is your functionality.

Regards
Rushi
 
Share this answer
 
Comments
Dalek Dave 17-May-11 3:28am    
Sounds Reasonable.
Look at handling the MouseDown and MouseUp events - you may also want to check for MouseMove or MouseLeave events and remove your code from the Click event to a general method.
You may also need to introduce a timer if you want the routine called repeatedly.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 17-May-11 3:10am    
That is correct, my 5, but it should be a custom control, not button.
Please see my answer.
--SA
Dalek Dave 17-May-11 3:28am    
Good Answer.
You cannot do it with a standard button, because a button does not expose events like "PressedDown" and "Released". You should create your own custom control looking like button but implementing such events using lower-level keyboard and mouse events. Don't derive your control class from Button, derive it from Control.

—SA
 
Share this answer
 
Comments
Dalek Dave 17-May-11 3:28am    
Sage Advice
Sergey Alexandrovich Kryukov 17-May-11 15:31pm    
Thank you, Dalek.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900