473,790 Members | 2,437 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Control.KeyDown

8 New Member
Control.KeyDown , C#.NET

I have a user control with several controls on it. I had the same code in all the controls to call the Winhelp or DO SOME STUFF. The code basically captured the F1 Key when the control had the focus. All worked fine, but I had up to 20 controls on a form and the same snippet of code below had to basically be repeated 20 times

1. Create an event for Control in IntitializeComp onent()
this.MyTextBox. KeydDown += new System.Windows. Fomrs.KeyEventH andler(this.MyT extBox_EventNam e);

2. Create the Event Handler for For the Above Control.KeyDown event

private void MyTextBox_KeyDo wn(object sender, System.Windows. Forms.KeyEventA rgs e)
{
if (e.KeyCode == Keys.F1)
{
DO SOME STUFF HERE;
}
}

I then made the code generic see the snippet below and used one routine for all the controls. Now the Event Handler is never called, nothing happens. What is missing or what else is needed for a simple solution?

Below is the Scenario

1.Create a generic event for all controls on the form in IntializeCompon ents()
this.KeydDown += new System.Windows. Forms.KeyEventH andler(this.MyG eneric_EventNam e_KeyDown);

2 .Create a generic event handler for all The Controls that we are interested in.

private void MyGeneric_Event Name_KeyDown(ob ject sender, System.Windows. Forms.KeyEventA rgs e)
{
foreach (Control c in this.Controls)
{
if (c is TextBox || c is ComboBox || c is CheckBox)
{
if (e.KeyCode == Keys.F1)
{
DO SOME STUFF HERE;
}
}
}
}
Sep 6 '06 #1
0 2130

Sign in to post your reply or Sign up for a free account.

Similar topics

3
4156
by: Peter Verburgh | last post by:
Is there an easy way to capture the keypress - keydown events from a LABEL control ? Standard the control doesn't handle these events. The label control inherits from the control class , and this class has the keypress - keydown event handlers. So i believe this must be possible ? k/Regards,
3
5129
by: Keith Smith | last post by:
Is there an easy way to make the {Enter} key take the cursor to the next control without using a KeyDown event on each control?
6
11089
by: Barguast | last post by:
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.
9
1427
by: Woody Splawn | last post by:
On a winform, how do I trap for the user pressing Control Delete? I thought perhaps something like the following in the keydown event of the grid, but the code below does not work. If e.KeyCode = Keys.ControlKey.Delete Then MsgBox("You pressed Control Delete") End If
0
1866
by: Peter | last post by:
I have a VB6 program which can receive Keydown events on an ActiveX control. The ActiveX control can't fire keydown events so I put a picturebox below the ActiveX control. I write codes in function picturebox_keydown in response to the keydown events on the ActiveX control. These can work well. But when I update these codes to vb.net I got a message 'UPGRADE_WARNING: PictureBox event Picture1.KeyDown can't be updated. Click to get more...
2
15460
by: bretth | last post by:
In a VB.Net Windows Forms application, I have a user control that handles mouse events. Another section of code programmatically adds a label to the control. I would like label to ignore all events allowing the user control to react to the mouse click. Setting the Enabled property on the label to False comes close, but I don't want the font color to change. Does anyone have an idea how .NET implements the code behind the Enabled...
0
1862
by: ghost | last post by:
i have a main form, with user controls populating it. i'm trying to capture a keyevent for the control that's populating the form but it never fires that event. the main form's keypreview property is set to true but when i assing the "keydown" event on the user control, nothing happens. i set a breakpoint in the event method and nothing...it never hits.
4
3294
by: boopsboops | last post by:
Hi thescripts people, I hope I'm in the right forum for Visual Basic Dotnet (VS 2005). I am trying to make a custom control in which you can nudge a point around using the arrow keys. Actually, the control is meant to be a simple drawing program. To test it out I have put the control on a Windows form which also contains several buttons. I have added a KeyDown event handler to the custom control (see code below). It responds fine to keys...
2
2578
by: GS | last post by:
I was trying to catch the control enter key sequence of a combo box in the keydown event, but I failed to se anything like control enter, neither Did I find in keypresssed event I tried google but no luck Do I have to go down to the level of capturing control keydown/press with time and then when enter key is pressed check the time? or is there some easier way?
0
9512
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10413
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10200
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10145
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9986
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7530
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6769
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3707
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.