0
votes

I have created what I call a "LabeledTextBoxWithLookupControl" which inherits from UserControl. I've put several of these controls on a form.

Now I'm beginning to think that this was a bad idea.

When I call TopLevelControl.SelectNextControl(this, true, true, true, true) from a KeyPress event assigned to the TextBox in the UserControl, it's actually selecting the next UserControl, where I actually want it to select the text box inside the next user control. The UserControl's CanSelect property returns true, but I don't see any easy way to change a UserControl's Control Style.

Also, when I use the Tab Order mode, I'd prefer it not consider the user control itself, but the the just the TextBox in inside the UserControl as candidate for tab order. Should I override the TabIndex and TabStop properties of the UserControl and make them point to the TabIndex and TabStop of the TextBox?

Also, should I expose just the properties of the controls themselves, or should I expose each control as a property to set these properties I want to be able to set, such as the Text property of the label control, the click event of the LookupControl and the Text property of the TextBox.

1
No repro. UserControl contains explicit code that passes the focus to its first child control if it ever gets the focus. Post a small repro project to a file sharing service or a paste bin if you want help with your problem. - Hans Passant
@Hans: I've had this problem with newly created UserControl types so I'm not sure I agree with your "no repro". - Jeff Yates

1 Answers

1
votes

If you don't want the UserControl to be a tab stop but rather it's contents, you have to make sure that it doesn't have the ControlStyles.Selectable style.

In the constructor of your UserControl add:

SetStyle(ControlStyles.Selectable, false);