Windows Develop Bookmark and Share   
 index > Windows Forms General > KeyDown and MouseDown events all at once. How can it be done?
 

KeyDown and MouseDown events all at once. How can it be done?

Hello everyone!

I have an issue here and I hope you can help me.
I have a list view. If the user press SHIFT and click with the left button, I am supposed to do some operation.

I created a global boolean shiftPressed variable and on the key down event I set this variable to true.
On the mouse down event I check if (shiftPressed && e.Button == MouseButton.LEFT) is equals to true

But this is not 100% OK because the user can just press shift, stop pressing, and then just left-click and the operation is still done.

What I need is to check when he left-click he stil is pressing the shift button.

Any one have ideas?

Thanks a lot!
Solum  Thursday, December 20, 2007 11:01 AM

hi Solum,

In KeyUp event you can reset that boolean. ( or set to false ).

Hope this will help

Thanks

Mahesh

Mahesh Kannan  Thursday, December 20, 2007 11:59 AM

Use the following in your buttondown event:

Code Block

if (Control.ModifierKeys == Keys.Shift)

If you don't, you will in certain circumstances end up with an invalid shiftPressed state.

Tergiver  Thursday, December 20, 2007 6:42 PM

hi Solum,

In KeyUp event you can reset that boolean. ( or set to false ).

Hope this will help

Thanks

Mahesh

Mahesh Kannan  Thursday, December 20, 2007 11:59 AM
Thanks a lot!
Easy solution that I didnt come up with Smile

Have a great xmas! Smile
Solum  Thursday, December 20, 2007 1:18 PM

Use the following in your buttondown event:

Code Block

if (Control.ModifierKeys == Keys.Shift)

If you don't, you will in certain circumstances end up with an invalid shiftPressed state.

Tergiver  Thursday, December 20, 2007 6:42 PM

You can use google to search for other answers

Custom Search

More Threads

• How can I conslidate multiple pages into 1 print job?
• Applying Visual Styles to form When Theme Service is not enabled.
• Visual studio resizing anchored controls
• Loading the controls of a MDI child form
• Reordering individual rows in a DataGridView
• Problem with calling a ProcessStartInfo from within application.
• "Fade out" form
• Accesing Checkbox in DatagridView,DataGridView is being filled from XML file.
• ListVIew and OnSelected Index Changed Event in vb.NET
• Custom control