468,457 Members | 1,801 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,457 developers. It's quick & easy.

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 2193
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by IMRAN SAROIA | last post: by
12 posts views Thread by CLEAR-RCIC | last post: by
1 post views Thread by clickon | last post: by
7 posts views Thread by Zytan | last post: by
5 posts views Thread by Finn Stampe Mikkelsen | last post: by
3 posts views Thread by kelvin.koogan | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.