.net - Changing the TabStop on controls after the form has loaded -
i have form group of dropdowns want keep out of tab order in cases. i've set tabstop property false , set true when want them in tab order. want include them in tab order when user clicks on 1 of dropdowns in group. accomplish this, i'm setting tabstop property of dropdowns true in enter event handler each of controls. produces strange behavior on enter. each of controls appears have of text selected (highlighted). expect control has focus behave that. can explain this? thanks!
i created simple form has same strange behavior. when form comes up, click on either of dropdowns mouse , you'll see:
here's code form in c#:
public partial class form1 : form { public form1() { initializecomponent(); } private void combobox1_enter(object sender, eventargs e) { combobox1.tabstop = combobox2.tabstop = true; } private void combobox2_enter(object sender, eventargs e) { combobox1.tabstop = combobox2.tabstop = true; } /// <summary> /// required designer variable. /// </summary> private system.componentmodel.icontainer components = null; /// <summary> /// clean resources being used. /// </summary> /// <param name="disposing">true if managed resources should disposed; otherwise, false.</param> protected override void dispose(bool disposing) { if (disposing && (components != null)) { components.dispose(); } base.dispose(disposing); } #region windows form designer generated code /// <summary> /// required method designer support - not modify /// contents of method code editor. /// </summary> private void initializecomponent() { this.combobox1 = new system.windows.forms.combobox(); this.combobox2 = new system.windows.forms.combobox(); this.suspendlayout(); // // combobox1 // this.combobox1.formattingenabled = true; this.combobox1.items.addrange(new object[] { "combobox1", "combobox2"}); this.combobox1.location = new system.drawing.point(12, 12); this.combobox1.name = "combobox1"; this.combobox1.size = new system.drawing.size(121, 21); this.combobox1.tabindex = 1; this.combobox1.tabstop = false; this.combobox1.text = "combobox1"; this.combobox1.enter += new system.eventhandler(this.combobox1_enter); // // combobox2 // this.combobox2.formattingenabled = true; this.combobox2.items.addrange(new object[] { "combobox1", "combobox2"}); this.combobox2.location = new system.drawing.point(12, 39); this.combobox2.name = "combobox2"; this.combobox2.size = new system.drawing.size(121, 21); this.combobox2.tabindex = 2; this.combobox2.tabstop = false; this.combobox2.text = "combobox2"; this.combobox2.enter += new system.eventhandler(this.combobox2_enter); // // form1 // this.autoscaledimensions = new system.drawing.sizef(6f, 13f); this.autoscalemode = system.windows.forms.autoscalemode.font; this.clientsize = new system.drawing.size(284, 77); this.controls.add(this.combobox2); this.controls.add(this.combobox1); this.name = "form1"; this.text = "form1"; this.resumelayout(false); } #endregion private system.windows.forms.combobox combobox1; private system.windows.forms.combobox combobox2; }
Comments
Post a Comment