feurich Posted July 27, 2005 Posted July 27, 2005 (edited) [csharp] private void cboImportset_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { // Catch the enter keypressed if (e.KeyChar = Keys.Enter) // { // Check if ImportSet already exists if so select ImportSet. // if ImportSet doesn' exists add it to ImportSet list. MessageBox.Show(e.KeyChar.ToString()); // } [/csharp] Errors are: - Cannot implicitly convert type 'char' to 'bool' - Property or indexer 'System.Windows.Forms.KeyPressEventArgs.KeyChar' cannot be assigned to -- it is read only - Cannot implicitly convert type 'System.Windows.Forms.Keys' to 'char' Edited July 27, 2005 by feurich Quote Trust the Universe
IngisKahn Posted July 27, 2005 Posted July 27, 2005 That shouldn't even compile. Your if statement is invalid. ( == ) Quote "Who is John Galt?"
feurich Posted July 27, 2005 Author Posted July 27, 2005 Sorry for that :eek: But even with the == inplace it doesn't compile. error is: Operator '==' cannot be applied to operands of type 'char' and 'System.Windows.Forms.Keys' I know I have to convert the e.KeyChar. But how. In VB.NET you have the Asc() function but what is that in C#???? Quote Trust the Universe
feurich Posted July 27, 2005 Author Posted July 27, 2005 No e.KeyCode I don't have e.Keycode in my intellisence... Also on a lot of website it says that there must be a e.KeyValue in the event arg. But I don't see it. Any info on that? Quote Trust the Universe
feurich Posted July 27, 2005 Author Posted July 27, 2005 ok found it This is it.... if (e.KeyChar == (char)13) Man, converting from VB.NET to CSharp isn't that easy :o :o :o Quote Trust the Universe
thenerd Posted July 27, 2005 Posted July 27, 2005 Are you sure? Try typing e.keycode anyway. I know I have it in vb.net. Quote
feurich Posted July 27, 2005 Author Posted July 27, 2005 Tried it I tried it but when i compile the code it says: 'System.Windows.Forms.KeyPressEventArgs' does not contain a definition for 'keycode' See my last post. That does the trick. Thanks for the effort. Quote Trust the Universe
Joe Mamma Posted July 27, 2005 Posted July 27, 2005 I am just guessing. . . but does this work? e.KeyChar.Equals(Keys.Enter) Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
Joe Mamma Posted July 27, 2005 Posted July 27, 2005 actually it doesnt but this does. bool isEqual = e.KeyChar == Convert.ToChar(Keys.Enter); which I would prefer rather than the (char) cast of #13 Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
Joe Mamma Posted July 27, 2005 Posted July 27, 2005 also. . . KeyCode is a member of KeyEventArgs but not KeyPressEventArgs. FYI order of events - KeyDown (a KeyEventHandler) KeyPress (a KeyPressEventHandler) KeyUp (a KeyEventHandler) Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
IngisKahn Posted July 27, 2005 Posted July 27, 2005 Why not e.KeyChar == '\r' Quote "Who is John Galt?"
Joe Mamma Posted July 28, 2005 Posted July 28, 2005 Why not e.KeyChar == '\r'Only that I can never remember escape sequences. :) Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
Anil_hyd Posted July 10, 2012 Posted July 10, 2012 private void LoginForm_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { button1_Click(sender, e); } }:) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.