By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,286 Members | 2,443 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,286 IT Pros & Developers. It's quick & easy.

Setting focus inside a Panel

P: n/a
I have several applications that use panels as screens, but I can *not* seem
to set the focus for a Textbox.

Panel1.BringToFront()
Panel1_Textbox.Focus()
' do something with a control on Panel1
Panel2.BringToFront()
Panel2_Textbox.Focus()
' do something with a control on Panel2

When the applications are running, I can almost see the Textbox controls
receiving focus for an instant, then Nothing has focus!

How do I set the Focus on the Textbox controls ... and have it STAY there?
Mar 21 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Mar 21, 10:18 pm, "jp2express" <useF...@joeswelding.bizwrote:
I have several applications that use panels as screens, but I can *not* seem
to set the focus for a Textbox.

Panel1.BringToFront()
Panel1_Textbox.Focus()
' do something with a control on Panel1
Panel2.BringToFront()
Panel2_Textbox.Focus()
' do something with a control on Panel2

When the applications are running, I can almost see the Textbox controls
receiving focus for an instant, then Nothing has focus!

How do I set the Focus on the Textbox controls ... and have it STAY there?
Normally,
textbox.focus gives focus. But if you lose focus for some reason and
still you want your textbox has the focus then you should:

Private Sub TextBox1_lostfocus(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles_ TextBox1.LostFocus

TextBox1.Focus()

End Sub

Therefore, when you textbox loses focus, it re-gains the focus.

Hope this helps.
Mar 21 '08 #2

P: n/a
Interesting trick! I will certainly give it a try. Thanks!

"kimiraikkonen" wrote:
On Mar 21, 10:18 pm, "jp2express" <useF...@joeswelding.bizwrote:
I have several applications that use panels as screens, but I can *not* seem
to set the focus for a Textbox.

Panel1.BringToFront()
Panel1_Textbox.Focus()
' do something with a control on Panel1
Panel2.BringToFront()
Panel2_Textbox.Focus()
' do something with a control on Panel2

When the applications are running, I can almost see the Textbox controls
receiving focus for an instant, then Nothing has focus!

How do I set the Focus on the Textbox controls ... and have it STAY there?

Normally,
textbox.focus gives focus. But if you lose focus for some reason and
still you want your textbox has the focus then you should:

Private Sub TextBox1_lostfocus(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles_ TextBox1.LostFocus

TextBox1.Focus()

End Sub

Therefore, when you textbox loses focus, it re-gains the focus.

Hope this helps.
Mar 21 '08 #3

P: n/a
Looks to me like such a "trick" would cause you to be in a loop with it
impossible to get "out of" the textbox!
--
Terry
"kimiraikkonen" wrote:
On Mar 21, 10:18 pm, "jp2express" <useF...@joeswelding.bizwrote:
I have several applications that use panels as screens, but I can *not* seem
to set the focus for a Textbox.

Panel1.BringToFront()
Panel1_Textbox.Focus()
' do something with a control on Panel1
Panel2.BringToFront()
Panel2_Textbox.Focus()
' do something with a control on Panel2

When the applications are running, I can almost see the Textbox controls
receiving focus for an instant, then Nothing has focus!

How do I set the Focus on the Textbox controls ... and have it STAY there?

Normally,
textbox.focus gives focus. But if you lose focus for some reason and
still you want your textbox has the focus then you should:

Private Sub TextBox1_lostfocus(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles_ TextBox1.LostFocus

TextBox1.Focus()

End Sub

Therefore, when you textbox loses focus, it re-gains the focus.

Hope this helps.
Mar 23 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.