C # obtain the value of the input number on the keyboard

Source: Internet
Author: User

/// <Summary>
/// Reload the processcmdkey event
/// </Summary>
/// <Param name = "MSG"> </param>
/// <Param name = "keydata"> </param>
/// <Returns> </returns>
Protected override bool processcmdkey (ref message MSG, keys keydata)
{
Int Index = dgvbaseslist. currentcell. rowindex;
String text = clipboard. gettext ();
Eventargs E = new eventargs ();
If (keydata = keys. Enter)
{
This. btnok_click (this, e );
}
Else if (keydata = keys. down)
{
If (index <dgvbaseslist. Rows. Count-1)
{
// Dgvbaseslist. Rows [index + 1]. Selected = true;
Dgvbaseslist. currentcell = dgvbaseslist [0, index + 1];
Txtno. Text = (dgvbaseslist. currentrow. index + 1). tostring ();
}
}
Else if (keydata = keys. UP)
{
If (index> 0)
{
Dgvbaseslist. currentcell = dgvbaseslist [0, index-1];
Txtno. Text = (dgvbaseslist. currentrow. index + 1). tostring ();
}
}
Else if (keydata> = keys. D0 & keydata <= keys. D9) | (keydata> = keys. numpad0 & keydata <= keys. numpad9 ))
{
String num = keycodetostr (keydata );
String num1 = num;
Int NO = int32.parse (txtno. Text. tostring () + num );
If (NO> dgvbaseslist. Rows. Count-1)
{
If (int32.parse (Num)> dgvbaseslist. Rows. Count)
{
Dgvbaseslist. currentcell = dgvbaseslist [0, dgvbaseslist. Rows. Count-1];
Txtno. Text = (dgvbaseslist. Rows. Count-1). tostring ();
}
Else if (int32.parse (Num)> 0)
{
Dgvbaseslist. currentcell = dgvbaseslist [0, int32.parse (Num)-1];
Txtno. Text = num. tostring ();
}
}
Else
{
Dgvbaseslist. currentcell = dgvbaseslist [0, no-1];
Txtno. Text = No. tostring ();
}
}
Return true;

}
[Dllimport ("user32.dll")]
Static extern int mapvirtualkey (uint ucode, uint umaptype );

Private Static char keycodetochar (Keys K)
{
Int nonvirtualkey = mapvirtualkey (uint) K, 2 );
Char mappedchar = convert. tochar (nonvirtualkey );
Return mappedchar;
}
Public static string keycodetostr (Keys K)
{
Char mappedchar = keycodetochar (k );
String STR = mappedchar. tostring ();
If (char. iswhitespace (mappedchar) | string. isnullorempty (STR) | mappedchar = '\ R' | mappedchar =' \ n' | mappedchar = keycodetochar (keys. f1 ))
{
Return K. tostring ();
}
Else
{
Return STR + "";
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.