Tabbing in a loop through a winform
-
14-07-2021 - |
Вопрос
I have an application where I have several forms. Its a C# windows-form based application build in .NET 4.O. I have several forms where the user enters the data. There are grids where data is displayed and whole lots of controls on the form. Believe me! its a mess of so many controls. I have to setup the TabIndex
for each control. I have literally disabled the TabStop
property of certain controls I don't want to be tabed into it. However, still once I go through the order I want, I TAB it, and it works but once it reaches the last box then it takes 3-4 times more tabbing to get to the first field. I tried disabling the TabStop
property for the controls I don't want. But I think there might be certain controls that I don't see but they might be included in the Tab property.
My question is that is there any way that I can set the TabStop
property of all the controls on the winform to false
and then set it to true
for the controls I want to include only.
I also open to if there is any other way I can implement this?
If further explanation is needed, let me know!
I have attached a picture thats the order I want and then loop back but somehow its not working. Just in addition there is also two panels in the form and I have disabled their TabStop
property to False
.
Решение
One simple explanation is that you lost a control underneath another one that overlaps it. Or it is located beyond the edges of the Form. A good tool to find it back is View + Other Windows + Document Outline.
If that doesn't help then diagnose it by adding a Label and a Timer. Write the Tick event handler like this:
private void timer1_Tick(object sender, EventArgs e) {
if (this.ActiveControl != null) label1.Text = this.ActiveControl.Name;
}
Другие советы
- Go to
View
menu and clickTab Order
. This will activate the tab-order selection mode on the form.TabIndex
value will be displayed as a number on each control. - Click on controls in order you need them to be tabbed. This will set appropriate values for
TabIndex
of controls. - After you finished, go to
View
menu and turn-offTab Order
. - Select controls you don't want to be tabbed and set
TabStop = false
.
You should try the following code:
foreach (Control ctrl in this.Controls)
ctrl.TabStop = false;
Also you can try to check the last tabindex. Then go to your form.designers.cs and find all controls with a greater tabindex and then remove them : add
ctrlTabStop = false;
I did not test any of this, so be careful : backup your *.designer.cs before.