Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

i am trying to enable specific key presses. i am having trouble with the period key and the decimal key. i tried this

 

Asc(e.KeyChar) = Keys.Decimal
Asc(e.KeyChar) = Keys.OemPeriod

 

but it doesn't seem to work... the first line does not respond to any key press, while the second line responds to pressing "n" lowercase... i am puzzled... anyone have an idea?

Posted

I don't understand what you are trying to do - it looks like you're trying to set the key that was was pressed from the event args - which you can't do. If you're simply trying to test if the 'period' was pressed you should:

 

if(Convert.ToInt32(e.KeyChar)==Convert.ToInt32('.'))
{
     //Do whatever
}

 

If Convert.ToInt32(e.KeyChar) = Convert.ToInt32("."c) Then
       'Do something
End If

Posted

i was trying to check whether a keypress is a period (in order to allow that keypress). thanks for the tip - works for me! :-)

 

Just wodering about the syntax though - could you explain the ("."c) - i am puzzled by the c....

 

If Convert.ToInt32(e.KeyChar) = Convert.[color=Red]ToInt32("."c)[/color] Then
       'Do something
End If

  • Leaders
Posted
The c indicates that the value is a Char constant. A Char is a value type that holds a single character (sort of like a 1-character fixed length string). Just like the "r" in 1.0r indicates that a value is a double, the "c" in "."c indicates that the value is a Char (as opposed to a string).
[sIGPIC]e[/sIGPIC]

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...