C#?и????????????????????????????
???????????? ???????[ 2013/9/23 15:32:12 ] ????????
??????? ?ж????? ????????????? ???????????????
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//?????????λ???? ???TextBox???
TextBox[??] arr;
private void Form1_Load(object sender?? EventArgs e)
{
//?????????
arr = new TextBox[3?? 3]{{textBox1??textBox2??textBox3}??
{textBox4??textBox5??textBox6}??
{textBox7??textBox8??textBox9}
};
}
/// <summary>
/// ?????????? ??? ?????????? ??????KeyPreView?????True
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Form1_KeyDown(object sender?? KeyEventArgs e)
{
//????????????????
TextBox txt = (TextBox)GetFocusedControl();
//?????????????????????ж????λ?? ???????????????Tag??????
int x = int.Parse(txt.Tag.ToString().Substring(0?? 1));
int y = int.Parse(txt.Tag.ToString().Substring(1?? 1));
if (e.KeyCode == Keys.Left)
{
if (y > 0)
{
arr[x?? y-1].Focus();
}
}
else if (e.KeyCode == Keys.Right)
{
if (y < 2)
{
arr[x??y + 1].Focus();
}
}
else if (e.KeyCode == Keys.Up)
{
if (x > 0)
{
arr[x-1?? y].Focus();
}
}
else if (e.KeyCode == Keys.Down)
{
if (x < 2)
{
arr[x+1?? y].Focus();
}
}
}
// DLL???????
[DllImport("user32.dll"?? CharSet = CharSet.Auto?? CallingConvention = CallingConvention.Winapi)]
private static extern IntPtr GetFocus();
/// <summary>
/// ?????н??????
/// </summary>
/// <param name="formControl"></param>
/// <returns></returns>
public static Control GetFocusedControl()
{
Control focusedControl = null;
try
{
IntPtr focusedHandle = GetFocus();
if (focusedHandle != IntPtr.Zero)
{
focusedControl = Control.FromChildHandle(focusedHandle);
}
}
catch { }
return focusedControl;
}
}
|
???????????????????????漰???????????????????SPASVOС??(021-61079698-8054)?????????????????????????