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

Setting focus to the Form


Hello experts,

I want to use Form_Keydown event in my program. However, it turns out
that one of the form controls is always in focus, so Form_Keydown event
is never invoked. I tried to set focus to the Form using command
frmName.SetFocus in Form_Paint event, however with no effect.

The only successful way I think of to set focus to Form is to .Enable =
False and .Enable = True all controls in Form_Paint event. This works
fine, but is resources and time consuming.

Is there any simpler way to set focus to the Form?

Thanks, Marko.

Dec 16 '06 #1
7 30305
Pygmalion,

You mean to activate a form?

http://msdn2.microsoft.com/en-us/lib....activate.aspx

Cor

"Pygmalion" <ma***@pinteric.comschreef in bericht
news:11**********************@80g2000cwy.googlegro ups.com...
>
Hello experts,

I want to use Form_Keydown event in my program. However, it turns out
that one of the form controls is always in focus, so Form_Keydown event
is never invoked. I tried to set focus to the Form using command
frmName.SetFocus in Form_Paint event, however with no effect.

The only successful way I think of to set focus to Form is to .Enable =
False and .Enable = True all controls in Form_Paint event. This works
fine, but is resources and time consuming.

Is there any simpler way to set focus to the Form?

Thanks, Marko.

Dec 16 '06 #2

There is no .Activate method for the Form. Maybe the problem is I use
VisualStudio 6.0?

Marko

Cor Ligthert [MVP] je napisal:
Pygmalion,

You mean to activate a form?

http://msdn2.microsoft.com/en-us/lib....activate.aspx

Cor

"Pygmalion" <ma***@pinteric.comschreef in bericht
news:11**********************@80g2000cwy.googlegro ups.com...

Hello experts,

I want to use Form_Keydown event in my program. However, it turns out
that one of the form controls is always in focus, so Form_Keydown event
is never invoked. I tried to set focus to the Form using command
frmName.SetFocus in Form_Paint event, however with no effect.

The only successful way I think of to set focus to Form is to .Enable =
False and .Enable = True all controls in Form_Paint event. This works
fine, but is resources and time consuming.

Is there any simpler way to set focus to the Form?

Thanks, Marko.
Dec 16 '06 #3

"Pygmalion" <ma***@pinteric.comwrote in message
news:11**********************@80g2000cwy.googlegro ups.com...
>
Hello experts,

I want to use Form_Keydown event in my program. However, it turns out
that one of the form controls is always in focus, so Form_Keydown event
is never invoked. I tried to set focus to the Form using command
frmName.SetFocus in Form_Paint event, however with no effect.

The only successful way I think of to set focus to Form is to .Enable =
False and .Enable = True all controls in Form_Paint event. This works
fine, but is resources and time consuming.

Is there any simpler way to set focus to the Form?

The form itself can never have "focus" when there are controls on it that
can have focus. To do what you want, set the form's KeyPreview property to
True. The form will then receive keyboard events (KeyUp, KeyDown, KeyPress)
before any controls on that form. However, there are some exceptions. For
example, if you have a command button whose Default property is True, the
form will not get the Enter key.

You also said (in another message) that you're using Visual Studio 6
(presumably VB6). Why then did you include a dotnet newsgroup? That's why
you got the answer you did from Cor. THAT was the problem, not that you're
using VB6.

--
Mike
Microsoft MVP Visual Basic

Dec 16 '06 #4

MikeD je napisal:
"Pygmalion" <ma***@pinteric.comwrote in message
news:11**********************@80g2000cwy.googlegro ups.com...

Hello experts,

I want to use Form_Keydown event in my program. However, it turns out
that one of the form controls is always in focus, so Form_Keydown event
is never invoked. I tried to set focus to the Form using command
frmName.SetFocus in Form_Paint event, however with no effect.

The only successful way I think of to set focus to Form is to .Enable =
False and .Enable = True all controls in Form_Paint event. This works
fine, but is resources and time consuming.

Is there any simpler way to set focus to the Form?


The form itself can never have "focus" when there are controls on it that
can have focus. To do what you want, set the form's KeyPreview property to
True. The form will then receive keyboard events (KeyUp, KeyDown, KeyPress)
before any controls on that form. However, there are some exceptions. For
example, if you have a command button whose Default property is True, the
form will not get the Enter key.

You also said (in another message) that you're using Visual Studio 6
(presumably VB6). Why then did you include a dotnet newsgroup? That's why
you got the answer you did from Cor. THAT was the problem, not that you're
using VB6.
Thanks, that solved the problem.

Sorry for dotnet newsgroup.

Marko.

--
Mike
Microsoft MVP Visual Basic
Dec 16 '06 #5

Another question. Is it possible to prevent control to obtain keyboard
event?
E.g., F8 is defined only for the form. If KeyDown catches that F8 is
pressed, it does stuff and disable others to get that key event.

Thanks, Marko.

Pygmalion je napisal:
The form itself can never have "focus" when there are controls on it that
can have focus. To do what you want, set the form's KeyPreview property to
True. The form will then receive keyboard events (KeyUp, KeyDown, KeyPress)
before any controls on that form. However, there are some exceptions. For
example, if you have a command button whose Default property is True, the
form will not get the Enter key.
Dec 18 '06 #6

"Pygmalion" <ma***@pinteric.comwrote in message
news:11*********************@n67g2000cwd.googlegro ups.com...
>
Another question. Is it possible to prevent control to obtain keyboard
event?
E.g., F8 is defined only for the form. If KeyDown catches that F8 is
pressed, it does stuff and disable others to get that key event.

If I understand correctly....assign 0 to the KeyCode parameter.

--
Mike
Microsoft MVP Visual Basic
Dec 18 '06 #7

MikeD je napisal:
"Pygmalion" <ma***@pinteric.comwrote in message
news:11*********************@n67g2000cwd.googlegro ups.com...

Another question. Is it possible to prevent control to obtain keyboard
event?
E.g., F8 is defined only for the form. If KeyDown catches that F8 is
pressed, it does stuff and disable others to get that key event.

If I understand correctly....assign 0 to the KeyCode parameter.

--
Mike
Microsoft MVP Visual Basic
Yes, you understood correctly. Assigning 0 to KeyCode parameter
helped.

Thanks, Marko

Dec 21 '06 #8

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

Similar topics

3
by: Jesper Dannemamm | last post by:
Hi I am having trouble setting focus on I tried using this script in the usercontrol's page_load sub to set focus on a textbox with the ID = "user_name": Page.RegisterStartupScript("focus",...
2
by: Andi B | last post by:
Greetings all, and many thanks for your helpful replies to my earlier post today. I have another question now, if you would be so kind again: How do I make it so that the cursor appears in a...
20
by: Arne | last post by:
During testing <div style="overflow:auto;"> in CSS I noticed the mousewheel would work in Mozilla only after I made a <a href="#">some text</a> link and clicked on that, within the div. It...
0
by: Shravan | last post by:
Hi, I have a Windows Forms Custom DataGrid, which is put in a usercontrol, which on setting DataSource is setting focus to grid. The call stack for setting the focus is as follows. This is not...
2
by: Mystery Man | last post by:
We have an MDI application that is not setting always setting focus to the newly corrected MDI. It is creating the form and it is the topmost but it does not have focus. The code we are using to...
2
by: Jesper | last post by:
Hi, I'm showing a usercontrol containing a textbox on the screen by clicking a notifyIcon in the taskpane. I use textBox.Focus() to set the focus for the texbox, and I also get a blinking...
3
by: Steve Yerkes | last post by:
There seems to be way too much confusion over how to set focus on the a field using a field validator. I looked all over the web and found people trying to do this, but not getting anywhere. There...
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...
5
by: Glenn T. Kitchen | last post by:
Hello All, Does anyone know how to set the focus to a textbox control on Page_Load? Thank you, Glenn
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...
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?
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
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
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.