Groups | Blog | Home
all groups > vb.net > february 2004 >

vb.net : setting the initial focus



Paras Wadehra
2/18/2004 6:55:23 PM
Set the picture box's Tab Index to 0.

--
Paras
Your One Stop Entertainment Guide - http://www.paras.2ya.com/


[quoted text, click to view]

raja NO[at]SPAM cs.indiana.edu
2/18/2004 10:50:09 PM
How does one set the initial focus to a control such as a picture box?

Suppose I have a form with a single picture box on it.
When the application starts to run I would like to set the focus to the
picture box so that it can respond to KeyDown events.

I tried placing a picBox.focus in a Form_load event handler but that didn't
seem to help.

Any suggestions?

Thanks in advance,
Adrian Forbes [ASP MVP]
2/18/2004 10:56:16 PM
Surely the picturebox doesn't have a KeyDown event?

[quoted text, click to view]

Armin Zingler
2/19/2004 12:17:22 AM
"Raja S." <raja@cs.indiana.edu> schrieb
[quoted text, click to view]

See the documentation on the Focus method describing the preconditions that
must be met to set the focus.


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
hirf-spam-me-here NO[at]SPAM gmx.at
2/19/2004 12:18:51 AM
* raja@cs.indiana.edu (Raja S.) scripsit:
[quoted text, click to view]

Assign the control the lowest 'TabIndex' and it will be focused
automatically.

--
Herfried K. Wagner [MVP]
raja NO[at]SPAM cs.indiana.edu
2/19/2004 2:41:29 AM
hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP]) writes:

[quoted text, click to view]

Thanks for the response but picture boxes don't seem to have the
tabindex/tabstop properies appearing in the properties window.

In form_load if I try to set

picbox.tabstop = true
picbox.tabindex = 0

the focus still doesn't go to the picture box on start up.

I'm able to place a pixbox.focus in a MouseEnter event handler and then I
get the behavior I'd like. But I presume there ought to be a more direct
way of having a picture box the initial focus on application startup.

What am I missing?

Thanks,
Cor
2/19/2004 8:38:38 AM
Raja,

Webform or windowsform, they act very different in this?

Cor

raja NO[at]SPAM cs.indiana.edu
2/19/2004 11:37:01 AM
"Cor" <non@non.com> writes:

[quoted text, click to view]

Windowsform

Thanks,
Raja

hirf-spam-me-here NO[at]SPAM gmx.at
2/19/2004 3:59:10 PM
* raja@cs.indiana.edu (Raja S.) scripsit:
[quoted text, click to view]

AFAIS pictureboxes cannot get the focus.

--
Herfried K. Wagner [MVP]
Adrian Forbes [ASP MVP]
2/20/2004 12:03:19 AM
[quoted text, click to view]

The picturebox has no key events so why bother with the focus? If your
ultimate goal cannot be achieved why spend time on it?

raja NO[at]SPAM cs.indiana.edu
2/20/2004 2:45:48 AM
"Adrian Forbes [ASP MVP]" <sorry@noemail.zzz> writes:

[quoted text, click to view]

Thanks for the follow-up. I have wondered why for a picture box there are
no keyevents in the event drop-down-combo-box. But interestingly VB.net
-does- allow me to write such an event handler:

Private Sub picBox_KeyDown(ByVal sender As System.Object, ByVal e As _
System.Windows.Forms.KeyEventArgs) Handles picBox.KeyDown
...
End Sub

As I mentioned in an earlier note, I am able to give the picture box focus
with:

Private Sub picBox_MouseEnter(ByVal sender As Object, ByVal e As _
System.EventArgs) Handles picBox.MouseEnter
picBox.Focus()
End Sub

and then it responds to KeyDown events. I'm wondering if there is a way for
it to get the initial focus automatically on startup.

Thanks,
AddThis Social Bookmark Button