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

setting the initial focus

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,
Raja
Nov 20 '05 #1
10 2145
Surely the picturebox doesn't have a KeyDown event?

"Raja S." <ra**@cs.indiana.edu> wrote in message
news:c1**********@hood.uits.indiana.edu...
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,
Raja

Nov 20 '05 #2
* ra**@cs.indiana.edu (Raja S.) scripsit:
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.


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

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #3
Set the picture box's Tab Index to 0.

--
Paras
Your One Stop Entertainment Guide - http://www.paras.2ya.com/
"Raja S." <ra**@cs.indiana.edu> wrote in message
news:c1**********@hood.uits.indiana.edu...
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,
Raja

Nov 20 '05 #4
"Raja S." <ra**@cs.indiana.edu> schrieb
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?


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

Nov 20 '05 #5
hi***************@gmx.at (Herfried K. Wagner [MVP]) writes:
Assign the control the lowest 'TabIndex' and it will be focused
automatically.


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,
Raja
Nov 20 '05 #6
Cor
Raja,

Webform or windowsform, they act very different in this?

Cor
Nov 20 '05 #7
"Cor" <no*@non.com> writes:
Webform or windowsform, they act very different in this?


Windowsform

Thanks,
Raja
Nov 20 '05 #8
* ra**@cs.indiana.edu (Raja S.) scripsit:
Assign the control the lowest 'TabIndex' and it will be focused
automatically.


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


AFAIS pictureboxes cannot get the focus.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #9
> What am I missing?

The picturebox has no key events so why bother with the focus? If your
ultimate goal cannot be achieved why spend time on it?
Nov 20 '05 #10
"Adrian Forbes [ASP MVP]" <so***@noemail.zzz> writes:
What am I missing?
The picturebox has no key events so why bother with the focus? If your
ultimate goal cannot be achieved why spend time on it?


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,
Raja
Nov 20 '05 #11

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

Similar topics

2
by: dsnyder | last post by:
This HTML has a bit of Javascript at the end that puts the initial focus on the userID field. It works great on Windows2000 running IE6, but the initial focus never goes to the userID field on...
1
by: Blake Versiga | last post by:
How do i set the focus on a Textbox upon initial display of the page?
1
by: Brian Henry | last post by:
I remember this from before but cant remember how to do it, its been over a year since i have... how do you set the initial focus to a text box on page load? isn't it a java script you have to do?...
0
by: LCAdeveloper | last post by:
Another newbie question I'm afraid. When I use the .Focus() or .Select() methods to set the initial control that has focus on a form, try as I might I cannot get the control to visually indicate...
4
by: Aung Thu | last post by:
Hi, there! I want to set focus on a control, of which TabIndex is not the first, when a form is loaded. In the form's load event, I have used Control.Focus() but it doesn't not work. 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...
1
by: rameshch45 | last post by:
How to set the initial focus on the cursor in my form's first field? I dont want to use javascript for that as I have many forms - is there any attribute to set?
1
by: ton | last post by:
Hi, I'm using Ajax to seach direct in a gridview. It works fine. I even keep the focus on the input text box. Here is my code: Protected Sub Page_Load(ByVal sender As Object, ByVal e As...
3
by: zacks | last post by:
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.