What use OnGotFocus?

P

Phill. W

How am I supposed to use a Control's Overridable On* Methods?
I'm obviously missing something very important about them but they
just don't seem to do anything for me :-(

I have a UserControl which contains, among other things, a TextBox.
I'm trying to override the UserControl's focus-getting behavious such
that, on calling [Control].Focus() - which is probably my problem
- the User Control /intercepts/ this and puts directly focus into the
TextBox.

I've tried handling the GotFocus Event on both the UserControl and
the TextBox, and now overriding the OnGotFocus method, but
(a) I never get focus into my TextBox and
(b) the Focus() method itself returns False, even though it and all
its "parent" controls are both Visible and Enabled.

Any suggestions gratefully received...

TIA,
Phill W.
 
C

Claes Bergefall

Something like this perhaps:

Protected Overrides Sub OnGotFocus(ByVal e As System.EventArgs)
myTextBox.Focus()
End Sub

Public Overrides ReadOnly Property Focused() As Boolean
Get
Return myTextBox.Focused
End Get
End Property


/claes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top