473,396 Members | 2,018 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Setting focus inside a Panel

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
3 5173
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: | last post by:
Hi, I am setting the NumericUpDown .Value property and the ValueChanged event is NOT being fired. Does this ONLY get fired when I change it on the UI and not programatically? Thanks
2
by: IMRAN SAROIA | last post by:
Hi! Please advise how to set focus to any control on Web and Windows Forms. Regards Imran
1
by: Jason | last post by:
I have created a c-sharp app that has keyup, keydown events tied to the form. The form also has some other controls, buttons, labels and 1 custom control that I made which inherits from user...
12
by: CLEAR-RCIC | last post by:
Hi, I'm having problems setting focus to a textbox on a web user contol on an asp.net web page. The following script works on normal asp.net pages: <script language="javascript"> function...
3
by: Mike Eaton | last post by:
Hi there, I've got what I hope is a simple problem to solve... Here's the back story: I have a windows form. On the form is a panel containing three textboxes. Also on the form is a text box...
3
by: hula | last post by:
Hello againe a "basic" question on UserControls. I have some UserControls inside a panel. Inside the controls i have checkboxes, comboboxes and textboxes. On change of any data inside the...
2
by: Rob | last post by:
I have a dynamically created User Control inside of a dynamically created Flow Layout Panel inside of a Tab control added at design time.... The form where the Tab Control resides is a Singleton...
3
by: nityaprashant | last post by:
how to set focus on textbox inside panel(asp panel) inside ajax update panel plz help me..it's urgent...
1
by: Farsheed Ashouri | last post by:
Hi everyone. I create a little browser with wxpython and IEHtmlWindow. But I have a little problem here. When I press enter in the html page, The focus goes to another panel. Why this happens? I...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.