How does C # make controls move up and down around? (ext.)
Http://wenwen.sogou.com/z/q231436494.htm
Capture Key Events (turn) for control keys such as up and down keys in WinForm
http://blog.csdn.net/jiankunking/article/details/47320439
Control The focus of not multiple controls (GO) in C # based on the left and right keys
There are several controls that control the focus of each control based on the next key;
public partial class Form1:form
{
Public Form1 ()
{
InitializeComponent ();
}
Defines a two-bit array to hold a TextBox control
textbox[,] arr;
private void Form1_Load (object sender, EventArgs e)
{
Initializing an array
arr = new textbox[3, 3]{{textbox1,textbox2,textbox3},
{textbox4,textbox5,textbox6},
{TEXTBOX7,TEXTBOX8,TEXTBOX9}
};
}
//<summary>
/ Form keyboard Events Note: Set the KeyPreview property to true before enabling this event
//</summary
//<param name= "sender" ></PARAM>
//<param name= "E" ></PARAM>
private void Form1_keydown (object sender, KeyEventArgs e)
{
& nbsp; //The control that gets the current focus first
textbox txt = (textbox) Getfocusedcontrol ();
Gets the corresponding position of the current focus control in the array this value is stored in the control's Tag property beforehand
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 Call Registration
[DllImport ("user32.dll", CharSet = CharSet.Auto, callingconvention = Callingconvention.winapi)]
private static extern IntPtr GetFocus ();
<summary>
The control that currently has focus
</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;
}
}
C # Winform Adaptive size Toggle Control focus (GO) by the up and down keys
Toggle control focus by the up and down keys (only valid for textbox)
Private voidTextbox2_keydown (Objectsender, KeyEventArgs e)
{
If(E.keyvalue== 40 ||E.keyvalue== 13)
{
Sendkeys.send ("{TAB}");
}
If(E.keyvalue== 38)
{
IntIndex= This. Textbox2.tabindex;
For(IntI= 0; I < this++)
{
if (this== (Index -< Span style= "color: #000000;" > 1 {
this< Span style= "color: #000000;" >. Controls[i]. Focus ();
break}
}
}
} /span>
Self-adapting size
Private voidForm1_sizechanged (Objectsender, EventArgs e)
{
If(This. Windowstate.tostring ()== "Maximized")
{
This. datagridview1.width= This. Size.width-35;
}
Else If(This. Windowstate.tostring ()== "Normal ")
{
this.datagridview1.width = This-35}
else
{
.datagridview1.width = this-35}
} /span>
C # About controls move up or down