Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted

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?

Posted

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

Howzit??

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...