473,466 Members | 1,639 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Setting a Controls Focus?

I have created a c-sharp app that has keyup, keydown events tied to the
form. The form also has some other controls, buttons, labels and 1 custom
control that I made which inherits from user control.

My problem is ... When I first start the app all my keyboard events work
fine and by doing debugging I can see that my form has the focus. After I
click on a button or my custom control the focus is shifted to those
controls and the keyup, keydown events no longer fire. So to fix this I
thought I would set the focus back to the form at the end of a button press
event. I went into this code in the debugger and the this.focus() returns
false which I think means focus was not given back to the main form but I
don't understand why. I have also tried setting the tabstop property on all
the buttons to false, but that didn't help. Once I click somewhere inside my
app then the keyup and keydown events no longer get called. Basically I want
the main form to always have focus I guess so that my keyup, and keydown
events fire.

Any ideas would be great !
Thanks
Jay
Nov 16 '05 #1
1 1879

Set the form's Keypreview attribute to ture in the designer. This allows
and keyboard events for controls to be registered with the form as well.

I have created a c-sharp app that has keyup, keydown events tied to the
form. The form also has some other controls, buttons, labels and 1 custom
control that I made which inherits from user control.

My problem is ... When I first start the app all my keyboard events work
fine and by doing debugging I can see that my form has the focus. After I
click on a button or my custom control the focus is shifted to those
controls and the keyup, keydown events no longer fire. So to fix this I
thought I would set the focus back to the form at the end of a button press
event. I went into this code in the debugger and the this.focus() returns
false which I think means focus was not given back to the main form but I
don't understand why. I have also tried setting the tabstop property on all
the buttons to false, but that didn't help. Once I click somewhere inside my
app then the keyup and keydown events no longer get called. Basically I want
the main form to always have focus I guess so that my keyup, and keydown
events fire.

Any ideas would be great !
Thanks
Jay

Nov 16 '05 #2

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
1
by: Rachel Suddeth | last post by:
I have an form where the whole display is a tab control (well, that plus a status bar.) I want to set the focus to the first TextBox on the first TabPage when it loads. I tried to put that into...
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...
8
by: Brad Isaacs | last post by:
Good morning friends, I am working with Visual Studio 2005, ASP.NET 2.0 I am working with the Login controls provided my .NET 2.0, trying to make the Login1 control UserName textbox obtain...
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
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...
1
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
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.