I'm using Windows Forms. I have a button that, when clicked, immediately disables itself (by setting btnName.Enabled = false
). To my horror, I've discovered that this triggers the AfterSelect
event of a different control. The documentation for Enabled
claims that disabled buttons can't be selected, so I suppose it makes sense that something else would be selected instantly. In fact, the stack trace event points to an external Windows.Forms.SelectNextIfFocused()
method. This gives me my question: How do I determine what will be selected when selecting a button disables it?
It's probably due to the tab order of the controls. Check out the "TabIndex" property on each control, which is an integer that indicates the order in which the controls will receive focus when, for example, you use the tab key on the keyboard or, in this case, when the control that currently has the focus becomes disabled.