Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (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 by feurich
Trust the Universe
Posted

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#????

Trust the Universe
Posted

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?

Trust the Universe
Posted

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

Trust the Universe
Posted

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.

Trust the Universe
Posted

I am just guessing. . .

 

but does this work?

 

e.KeyChar.Equals(Keys.Enter)

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.

Posted

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

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.

Posted

also. . .

KeyCode is a member of KeyEventArgs but not KeyPressEventArgs.

 

FYI

order of events -

KeyDown (a KeyEventHandler)

KeyPress (a KeyPressEventHandler)

KeyUp (a KeyEventHandler)

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.

Posted
Why not e.KeyChar == '\r'
Only that I can never remember escape sequences. :)

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.

  • 6 years later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...