473,382 Members | 1,563 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

C#NET2008 KeyPreview

126 100+
Hi Good Guys,
I am back with interesting problem.
I need your help. Please help me.

As instructed to allow users to exit from FORM when press ESC key.

The coding generated these 2 Error Messages:
Error 1 The best overloaded method match for 'System.Windows.Forms.KeyEventArgs.KeyEventArgs(Sy stem.Windows.Forms.Keys)' has some invalid arguments

Error 2 Argument '1': cannot convert from 'method group' to 'System.Windows.Forms.Keys'

Here are the coding that causes it:

Expand|Select|Wrap|Line Numbers
  1.  
  2. private void FrmSales_Load(object sender, EventArgs e)
  3. {
  4.  
  5.   this.KeyPreview = true;
  6.   this.KeyDown += new System.Windows.Forms.KeyEventArgs(this.FrmMyOwnCoding_KeyDown); 
  7.  
  8. }
  9.  
Oct 14 '10 #1

✓ answered by Christian Binder

KeyDown is an event of delegate type KeyEventHandler and not KeyEventArgs!

Expand|Select|Wrap|Line Numbers
  1. this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.FrmMyOwnCoding_KeyDown); 
  2.  
  3. // Instead of
  4.  
  5. this.KeyDown += new System.Windows.Forms.KeyEventArgs(this.FrmMyOwnCoding_KeyDown); //WRONG!
  6.  

4 2292
Christian Binder
218 Expert 100+
KeyDown is an event of delegate type KeyEventHandler and not KeyEventArgs!

Expand|Select|Wrap|Line Numbers
  1. this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.FrmMyOwnCoding_KeyDown); 
  2.  
  3. // Instead of
  4.  
  5. this.KeyDown += new System.Windows.Forms.KeyEventArgs(this.FrmMyOwnCoding_KeyDown); //WRONG!
  6.  
Oct 14 '10 #2
Curtis Rutland
3,256 Expert 2GB
To save yourself the trouble of having to remember the delegate types for all the events, you can just type the this.KeyDown += and push TAB twice. It will generate the delegate and the method for you.

Alternatively, you can set this from the designer. Select the form's title bar, and in the Properties window, select the Events button. Then find your event, and double click it. It will create a method, and attach a handler in the .Designer.cs file.
Oct 14 '10 #3
lenniekuah
126 100+
Hullo Bro Christian,
Praise the Lord for your generousity in sharing information with me to help me. I have learned something new logically. Thank you very much.

May the Lord Jesus Bless you and Family.


Cheers,
Lennie
Oct 14 '10 #4
lenniekuah
126 100+
Hi Curtis,
Thank you very much for sharing information to help me. I have also tried out your suggestion and it working very well as well. Awesome....Yaa....hoooo
Oct 14 '10 #5

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

Similar topics

1
by: Rene | last post by:
Hi, I am running is some problems with the KeyPreview and KeyPress events. The KeyPress event is only triggered when there this an focusable control on the form. When all controls are disabled...
3
by: Vadim Rapp | last post by:
Hi: On my form, I have textbox and combo box. Form's KeyPreview = True. It does work for the textbox, but not for the combo. I.e. Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As...
13
by: HABJAN ®iga | last post by:
I'am using form's keypreview property & keydown (on form) to look for hotkeys (alt+?) Everything works fine, except when i have focus on combobox. Then the event on form isn't raised. Can...
9
by: Charles Law | last post by:
I have asked a similar question to this before, but have not found a satisfactory answer yet, so I thought I would ask it in another way. KeyPreview, for a form, handily allows keys to be...
2
by: RvGrah | last post by:
I have always found the form-level KeyPreview feature near useless, as there was a bug that allowed ComboBoxes to ignore it. In VS 2005 I've confirmed that it now woks in Combos. Is there anything...
1
by: Ryan Liu | last post by:
Hi, I know Form has a KeyPreview property, is there a similar property that can be used to control mouse event that is only processed at the from level, not the controls on it? I am asking...
0
by: Marc | last post by:
Hello, I have converted a project from .NET2005 to .NET2008 RTM I have also converted the project to use .NET Framework3.5 (as the project will only be in Beta in a few month). My project is...
2
by: lenniekuah | last post by:
Hullo Good Friends, I need your help. Please help me. I am using C#NET2008 to develop Window application I am trying to retrieve Sales Transaction and print it on WORD Document as statement...
2
by: lenniekuah | last post by:
Hullo Good Friends, I need your help again, please help me. I am using C#NET2008 for Window Application. Being requested to use ListBox to display 2 columns of data, i.e. OrderNumber, ...
9
by: lenniekuah | last post by:
Hullo Good Guys, I need your help. I am very puzzled about using WITH with C#NET2008. The coding below when used in VB.NET I will be using WITH : Wth me.ListBoxCust .ColumnWidth =...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.