|
ms
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Control-clickWhen a control's 'Click' event is triggered, is there a way I can test
whether the CTRL / Alt / Shift keys are pressed as well? I've thought about capturing KeyDown events before the click but this assumes that the control is in focus which won't necessarily be so. You can capture this in the KeyDown() and KeyUp() event
Using either e.Modifiers or checking if e.Control || e.Shift || e.Alt equals to true Gabriel Lozano-Morán Show quoteHide quote "Barguast" <ItsLikeMadeUpNSt***@Email.com> wrote in message news:7B0DA1F0-B310-4C06-9EAE-F6862ABC850D@microsoft.com... > When a control's 'Click' event is triggered, is there a way I can test > whether the CTRL / Alt / Shift keys are pressed as well? I've thought > about > capturing KeyDown events before the click but this assumes that the > control > is in focus which won't necessarily be so. But as I said, the control won't necessarily be in focus when the CTRL / Alt
/ Shift key is pressed which means the KeyDown / KeyUp events won't be triggered. Show quoteHide quote "Gabriel Lozano-Morán" wrote: > You can capture this in the KeyDown() and KeyUp() event > > Using either e.Modifiers or checking if e.Control || e.Shift || e.Alt equals > to true > > Gabriel Lozano-Morán > > "Barguast" <ItsLikeMadeUpNSt***@Email.com> wrote in message > news:7B0DA1F0-B310-4C06-9EAE-F6862ABC850D@microsoft.com... > > When a control's 'Click' event is triggered, is there a way I can test > > whether the CTRL / Alt / Shift keys are pressed as well? I've thought > > about > > capturing KeyDown events before the click but this assumes that the > > control > > is in focus which won't necessarily be so. > > > Barguast,
You can capture the keyevents if you set the keypreview to true on the form. That way when ever the form has the focus, you could get the Keys pressed. Show quoteHide quote "Barguast" <ItsLikeMadeUpNSt***@Email.com> wrote in message news:ED944675-D284-4F73-85FF-9BF7BEF4EE4E@microsoft.com... > But as I said, the control won't necessarily be in focus when the CTRL / Alt > / Shift key is pressed which means the KeyDown / KeyUp events won't be > triggered. > > "Gabriel Lozano-Morán" wrote: > > > You can capture this in the KeyDown() and KeyUp() event > > > > Using either e.Modifiers or checking if e.Control || e.Shift || e.Alt equals > > to true > > > > Gabriel Lozano-Morán > > > > "Barguast" <ItsLikeMadeUpNSt***@Email.com> wrote in message > > news:7B0DA1F0-B310-4C06-9EAE-F6862ABC850D@microsoft.com... > > > When a control's 'Click' event is triggered, is there a way I can test > > > whether the CTRL / Alt / Shift keys are pressed as well? I've thought > > > about > > > capturing KeyDown events before the click but this assumes that the > > > control > > > is in focus which won't necessarily be so. > > > > > > Thanks for yours replies, but I've just found out about the static
'System.Windows.Forms.ModifierKeys' property which can be checked during the click event. For example: private void Cell_Click (object sender, EventArgs e) { if ((Control.ModifierKeys & Keys.Control) == Keys.Control) { // The control has been CTRL-Clicked } } That'll do the trick :) Show quoteHide quote "Pipo" wrote: > Barguast, > > You can capture the keyevents if you set the keypreview to true on the form. > That way when ever the form has the focus, you could get the Keys pressed. > > > > "Barguast" <ItsLikeMadeUpNSt***@Email.com> wrote in message > news:ED944675-D284-4F73-85FF-9BF7BEF4EE4E@microsoft.com... > > But as I said, the control won't necessarily be in focus when the CTRL / > Alt > > / Shift key is pressed which means the KeyDown / KeyUp events won't be > > triggered. > > > > "Gabriel Lozano-Morán" wrote: > > > > > You can capture this in the KeyDown() and KeyUp() event > > > > > > Using either e.Modifiers or checking if e.Control || e.Shift || e.Alt > equals > > > to true > > > > > > Gabriel Lozano-Morán > > > > > > "Barguast" <ItsLikeMadeUpNSt***@Email.com> wrote in message > > > news:7B0DA1F0-B310-4C06-9EAE-F6862ABC850D@microsoft.com... > > > > When a control's 'Click' event is triggered, is there a way I can test > > > > whether the CTRL / Alt / Shift keys are pressed as well? I've thought > > > > about > > > > capturing KeyDown events before the click but this assumes that the > > > > control > > > > is in focus which won't necessarily be so. > > > > > > > > > > > > Indeed, though it is not the Form's ModifierKeys, but Form inherits from
Control so ... There is also the static Control.MouseButtons. -- Happy Coding! Morten Wennevik [C# MVP] Sorry i totally misunderstood the question. Hope this can help you get
started: [System.Runtime.InteropServices.DllImport("User32", EntryPoint="GetKeyState", ExactSpelling=false, CharSet=System.Runtime.InteropServices.CharSet.Ansi, SetLastError=true)] private static extern int GetKeyState(long nVirtKey); private const int VK_CONTROL = 0x11; private void button1_Click(object sender, System.EventArgs e) { MessageBox.Show(GetKeyState(VK_CONTROL).ToString()); } Gabriel Lozano-Morán Show quoteHide quote "Barguast" <ItsLikeMadeUpNSt***@Email.com> wrote in message news:ED944675-D284-4F73-85FF-9BF7BEF4EE4E@microsoft.com... > But as I said, the control won't necessarily be in focus when the CTRL / > Alt > / Shift key is pressed which means the KeyDown / KeyUp events won't be > triggered. > > "Gabriel Lozano-Morán" wrote: > >> You can capture this in the KeyDown() and KeyUp() event >> >> Using either e.Modifiers or checking if e.Control || e.Shift || e.Alt >> equals >> to true >> >> Gabriel Lozano-Morán >> >> "Barguast" <ItsLikeMadeUpNSt***@Email.com> wrote in message >> news:7B0DA1F0-B310-4C06-9EAE-F6862ABC850D@microsoft.com... >> > When a control's 'Click' event is triggered, is there a way I can test >> > whether the CTRL / Alt / Shift keys are pressed as well? I've thought >> > about >> > capturing KeyDown events before the click but this assumes that the >> > control >> > is in focus which won't necessarily be so. >> >> >>
Other interesting topics
exchanging data between a win32 application (service) and a c# application (service)
#define preprocessor Form Post - Session Values Is there any tool may provide the functionity changing variable's name automaticlly through entire c volatile - small question network assembly list attributes(xml) Is there any equivalent function in C# for the windows functions such as PurgeComm MSOffice component : AddTextBox how to Get and set desktop image in C#? |
|||||||||||||||||||||||