Reputation: 1452
I have a pretty complex UI with hundreds of control/label on it. I want to set tabstop value as false for each label as below
//in MyForm.designer.cs
Label myLabel;
private void InitializeComponent()
{
this.myLabel = new Label();
this.myLabel.TabIndex = 1;
...
}
// in MyForm.cs
this.myLabel.TabStop = false;
But it is not working. Is there any way to set the tabstop value so that tab is not stopped at myLabel??
Upvotes: 0
Views: 8380
Reputation: 1
(label as System.Windows.Forms.Control).TabStop = false;
Label control hides the TabStop property. It is annoying because one has to set its tab stop to be one less than tab stop of corresponding control, increasing number of tab stop indices. Loading controls dynamically is a pain unless one disables tab stops on labels and other non-input controls.
Note designer will intermittently toss an exception on line setting TapStop to false.
Upvotes: 0
Reputation: 1
Please try this:
Private Sub Label1_Enter(sender As Object, e As EventArgs) Handles Label1.Enter
SendKeys.Send("{TAB}")
End Sub
Private Sub Label2_Enter(sender As Object, e As EventArgs) Handles Label2.Enter
SendKeys.Send("{TAB}")
End Sub
Private Sub Label3_Enter(sender As Object, e As EventArgs) Handles Label3.Enter
SendKeys.Send("{TAB}")
End Sub
Upvotes: 0
Reputation: 3711
If you are using standard Label control, it should not get focus. Behavior of Label is to just forward focus to first control that can get it (e.g. TextBox). However, do notice that if you have control that can have input focus (e.g. TextBox), once that control gets focus, focus will stay with it regardless of TabStop property.
Upvotes: 2
Reputation: 47726
Try setting the tabindex to -1, that usually causes tabs to be skipped in most implementations that I have used.
Upvotes: 1