开发者

UserControls: What am I missing?

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 LookupCon开发者_开发知识库trol and the Text property of the TextBox.


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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜