31

I have a form with 2 buttons and 2 labels.

I want to set button 1 = tabIndex = 0, button 2 = tabIndex = 1 and I do not want to set a tabIndex to the 2 labels, meaning that if the user presses tab, it'll go from button 1 to button 2.

How would I go about doing this?

JJ.
  • 9,580
  • 37
  • 116
  • 189

6 Answers6

47

Just set the TabStop property of the Labels to false and the TabIndex property of the Buttons to whatever you want. You can do it right in the Properties window of the designer.

itsme86
  • 19,266
  • 4
  • 41
  • 57
  • 10
    Labels and other controls, such as radio buttons do not have a TabStop property...at least I'm not seeing it in the properties window. – JJ. Sep 04 '12 at 21:11
  • 9
    TabStop actually isn't relevant for labels. .NET is smart enough to know you should never be able to Tab to one: http://msdn.microsoft.com/en-us/library/1dsccs1d.aspx – itsme86 Sep 04 '12 at 21:16
2

In my case, all my Labels don't have TabStop property.

I cannot even set the TabIndex to -1 either, since it will say Property value not valid.

But I notice that once I run the application, regardless on what value I have on my TabIndex for all my labels, it doesn't stop on any labels when I press my Tab on my keyboard.

The reason for this is that Label controls do not get focus. The only way to cause a Label control to gain focus is to call the Label.Focus method.

For more info, you can read this forum: MSDN Forum.

Willy David Jr
  • 8,604
  • 6
  • 46
  • 57
1
button1.TabIndex = 0;
button2.TabIndex = 1;

Labels by default have TabStop set to false which means they shouldn't get focus by pressing tab.

coolmine
  • 4,427
  • 2
  • 33
  • 45
0

set the label's tabstop properties to false?

http://msdn.microsoft.com/en-us/library/system.windows.forms.control.tabstop.aspx

otherwise, just set the label's tabindex value to the value before the button. Then you can use accelerator keys to click on the button.

Beth
  • 9,531
  • 1
  • 24
  • 43
  • 7
    Labels and other controls, such as radio buttons do not have a TabStop property...at least I'm not seeing it in the properties window. – JJ. Sep 04 '12 at 21:12
0

As per the documentation on MSDN, The TabStop property is not relevant for the Label class, so setting TabStop to true has no effect. So i will set both label's tab indexes into 0 and button 1 will get tab index 1 and button 2 will get tab index 2

Damith
  • 1,982
  • 3
  • 28
  • 42
0

In the design environment you can Tab the labels. However when you run the windows form, you cannot Tab the labels. So you don't need TabStop or adjusting the Tab Index for the labels.

RezaNikfal
  • 927
  • 11
  • 22