473,385 Members | 1,740 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,385 software developers and data experts.

Setting Control Focus

I am working on an application that has a UI that supports multiuple
functions by means of a group of "plug ins". Each plugin is a class
library. Each plugin contains a User Control that defines the controls
for that plugin's main form. The UI has a PictureBox control that is
nothing but a contain to add the UserControl from the selected plugin,
so that when the user selects a plugin, the main form changes
appearance to the UserControl in the selected plugin. When the UI
first launches, it loads the plugin from the last time the app was
shut down.

My problem is this. Whether the application first launches or the user
selects a different plugin, I cannot get the first control in the
UserControl to have focus. Each plugin's UserControl has a special
Initialize method that the plugin inovkes when it is loaded to set
some initial values. In one plugin, it populates a ComboBox. I have a
statement in the UserControl's Initialize method to set the focus to
the first control in the UserControl, but it doesn't seem to work. The
first control in each plugin's UserControl never gets focus
automatically, I have to click in the control for it to get focus.

Any idea how I can achieve this? I have tried to invoke the first
control's Select method instead of the Focus method and that doesn't
help.
Aug 4 '08 #1
3 2420
On Aug 4, 3:55 pm, za...@construction-imaging.com wrote:
I am working on an application that has a UI that supports multiuple
functions by means of a group of "plug ins". Each plugin is a class
library. Each plugin contains a User Control that defines the controls
for that plugin's main form. The UI has a PictureBox control that is
nothing but a contain to add the UserControl from the selected plugin,
so that when the user selects a plugin, the main form changes
appearance to the UserControl in the selected plugin. When the UI
first launches, it loads the plugin from the last time the app was
shut down.

My problem is this. Whether the application first launches or the user
selects a different plugin, I cannot get the first control in the
UserControl to have focus. Each plugin's UserControl has a special
Initialize method that the plugin inovkes when it is loaded to set
some initial values. In one plugin, it populates a ComboBox. I have a
statement in the UserControl's Initialize method to set the focus to
the first control in the UserControl, but it doesn't seem to work. The
first control in each plugin's UserControl never gets focus
automatically, I have to click in the control for it to get focus.

Any idea how I can achieve this? I have tried to invoke the first
control's Select method instead of the Focus method and that doesn't
help.
what if the plugin interface you define which control should have teh
focus?
in this case the container is responsible to give focus when needs to
(like in onLoad)
Aug 4 '08 #2
On Mon, 04 Aug 2008 12:55:36 -0700, <za***@construction-imaging.comwrote:
[...]
My problem is this. Whether the application first launches or the user
selects a different plugin, I cannot get the first control in the
UserControl to have focus. [...]

Any idea how I can achieve this? I have tried to invoke the first
control's Select method instead of the Focus method and that doesn't
help.
A concise-but-complete code sample would go a long way.

That said, the first thing I'd suggest is to stop abusing the PictureBox
class. It's not a container control. Use something more appropriate,
like Panel or even UserControl (both of which are intended for use as
containers).

It's possible (I didn't look into it closely myself) that the PictureBox
class just doesn't accept focus. That may have implications for
attempting to set focus to it or its children.

Pete
Aug 4 '08 #3
On Aug 4, 4:23*pm, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
On Mon, 04 Aug 2008 12:55:36 -0700, <za...@construction-imaging.comwrote:
[...]
My problem is this. Whether the application first launches or the user
selects a different plugin, I cannot get the first control in the
UserControl to have focus. [...]
Any idea how I can achieve this? I have tried to invoke the first
control's Select method instead of the Focus method and that doesn't
help.

A concise-but-complete code sample would go a long way.

That said, the first thing I'd suggest is to stop abusing the PictureBox *
class. *It's not a container control. *Use something more appropriate, *
like Panel or even UserControl (both of which are intended for use as *
containers).

It's possible (I didn't look into it closely myself) that the PictureBox *
class just doesn't accept focus. *That may have implications for *
attempting to set focus to it or its children.
Thanks for the suggestions.

After plugging away on thisd I figured out what was missing. After I
add the plugin's UserControl to the PictureBox's controls, I then
invoke the Select method for PictureBox.Controls[0].

And as far as using a PictureBox control as a container, I did not do
the design, but I will pass along your comments to the person who did.
Aug 4 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: IMRAN SAROIA | last post by:
Hi! Please advise how to set focus to any control on Web and Windows Forms. Regards Imran
2
by: MLH | last post by:
A form named frmVehicleEntryForm has a number of textbox controls who's OnGotFocus property setting is an expression... =Change2Green() Change2Green() looks something like this... Dim MyControl...
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...
2
by: Sridhar | last post by:
Hi, I have a question. I have created a user control which contains a textbox and a button. we will enter some search word in the textbox and hit the button. Then we will get a pop-up with the...
1
by: clickon | last post by:
For testing purposes i have got a 2 step WizardControl. Eqach step contains a text box, TextBox1 and TextBox2 respectively. If i put the following code in the respective activate event handlers...
1
by: clickon | last post by:
For testing purposes i have got a 2 step WizardControl. Eqach step contains a text box, TextBox1 and TextBox2 respectively. If i put the following code in the respective activate event handlers for...
7
by: Zytan | last post by:
I want to set a control in a form to have the default focus. This is not the accept button -- that's set to a button when is 'clicked' when you press ENTER. I want a textbox to have the focus...
5
by: Finn Stampe Mikkelsen | last post by:
Hi How can i set a focus to a textbox in my codebehind page?? I have this WebForm, that takes information from a user and 2 buttons on the form. One that takes action on the entered...
3
by: kelvin.koogan | last post by:
I have a number of controls on a tab page. I want to validate them all when the user tries to leave the tab. I then want to highlight the first control which fails validation. How can I do this? I...
2
by: angi35 | last post by:
I hope this is an easy question for someone out there. In Access 2000…I have a MainForm with a tab control (MAIN TABS) with 7 tabs. Within each tab is a SubForm. Within each SubForm is a tab...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.