Last active
February 14, 2020 03:09
-
-
Save ThoenigAdrian/1c58cce625b53f53654b04682506d9f5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void TabDefault() | |
{ | |
// The idea is as a User I expect the Tab Button to go from left to right and from top to bottom. | |
// Unfortunately this isn't the default behaviour in WinForms hence this method. | |
// It will go through all Controls and sort them by their x and y coordinates and set a sane set of Tab Indices | |
// This saves Maintainence because now you don't need to adapt Tab Indices when you add/remove a control | |
List<Control> tabAbleControls = new List<Control>(); | |
foreach (Control c in Controls) | |
{ | |
if(c.TabStop) | |
{ | |
tabAbleControls.Add(c); | |
} | |
} | |
tabAbleControls = tabAbleControls.OrderBy(o=> o.Location.Y).ThenBy( o=> o.Location.X).ToList(); | |
for(int i = 0; i < tabAbleControls.Count; i++) | |
{ | |
tabAbleControls[i].TabIndex = i; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment