AndyMC Posted April 9, 2003 Posted April 9, 2003 Hello there, I have trouble with the Control.Focus method. When I try to set the input focus on a textBox by using myTextbox.Focus() I get a "false" back and no focus is being set. The help explains: "A control can be selected and receive input focus if all of the following are true: its ControlStyles.Selectable style bit is set to true, it is contained in another control, and all its parent controls are both visible and enabled." So how can I ensure all the above mentioned conditions in a smart way? Does anybody know? Thanks, Andy Quote
Moderators Robby Posted April 9, 2003 Moderators Posted April 9, 2003 It's parent can be the Form, Panel, GroupBox etc. Quote Visit...Bassic Software
AndyMC Posted April 9, 2003 Author Posted April 9, 2003 Hi Robby, thanks for your answer. As the parent of the textbox is a user control. I tried the following code in the constructor of the user control (after initialize components): Me.Visible = True Me.Enabled = True Me.txtName.Visible = True Me.txtName.Enabled = True Me.txtName.Focus() But that didn't work too. As my textbox "txtName" is not a textbox but an extended control derived from Forms.Textbox I could imagine an overloaded "Focus"-method in my extendedTextbox where automatically everything will be done what has to be done (enable and make visible all parent controls). But how would I achieve that "automatically"? Any ideas? Quote
Cywizz Posted April 9, 2003 Posted April 9, 2003 Put the code in the parent's load event, not the constructor. The constructor gets fired before the parent and it's controls are added. Cheers Quote Howzit??
AndyMC Posted April 10, 2003 Author Posted April 10, 2003 Unfortunately it makes no difference if constructor or load. It still doesn't work. Has nobody the same problem??? Quote
*Gurus* divil Posted April 10, 2003 *Gurus* Posted April 10, 2003 You can't focus a control unless it's visible. Try, in the form's Load event, first showing the form (Me.Show()) and then setting the focus after that. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.