473,395 Members | 1,530 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.

Focus() in Control vs. UserControl

Hi,

I am in the process of writing a custom control. In the OnMouseDown
method I call this.Focus() to enable the control to receive keystrokes
in OnKeyDown(). My control is hosted in a MDI form.

Originally my control inherited from UserControl, but then the call to
this.Focus() returned false and no keypresses were received. The I
changed it to inherit from Control and everything works as expected.

Why doesn't it work when I inherit from UserControl?

thanks,
Michael

Oct 19 '07 #1
2 5335
UserControl is a container Control, which is designed to host other Controls
in a composite form.

--
HTH,

Kevin Spencer
Chicken Salad Surgeon
Microsoft MVP

"milund" <mv****@gmail.comwrote in message
news:11*********************@q5g2000prf.googlegrou ps.com...
Hi,

I am in the process of writing a custom control. In the OnMouseDown
method I call this.Focus() to enable the control to receive keystrokes
in OnKeyDown(). My control is hosted in a MDI form.

Originally my control inherited from UserControl, but then the call to
this.Focus() returned false and no keypresses were received. The I
changed it to inherit from Control and everything works as expected.

Why doesn't it work when I inherit from UserControl?

thanks,
Michael

Oct 19 '07 #2
So it is in this case correct to inherit from control - the reason for
inheriting from a usercontrol is simply that is what I was given by a
wizard I ran, so I never gave it mouch thought until I ran into
problems ;-)

Thanks for the answer.
Michael
On 19 Okt., 14:26, "Kevin Spencer" <unclechut...@nothinks.comwrote:
UserControl is a container Control, which is designed to host other Controls
in a composite form.

--
HTH,

Kevin Spencer
Chicken Salad Surgeon
Microsoft MVP

"milund" <mvl...@gmail.comwrote in message

news:11*********************@q5g2000prf.googlegrou ps.com...
Hi,
I am in the process of writing a custom control. In the OnMouseDown
method I call this.Focus() to enable the control to receive keystrokes
in OnKeyDown(). My control is hosted in a MDI form.
Originally my control inherited from UserControl, but then the call to
this.Focus() returned false and no keypresses were received. The I
changed it to inherit from Control and everything works as expected.
Why doesn't it work when I inherit from UserControl?
thanks,
Michael- Skjul tekst i anførselstegn -

- Vis tekst i anførselstegn -

Oct 22 '07 #3

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

Similar topics

3
by: Daisy | last post by:
I've started writing a listview, which currently draws my list to a pane, and onclick, works out which row you've clicked on, from the co-ordinates of the mouse, sets the .Selected property to the...
0
by: Miquel | last post by:
Hi all. I felt frustrated when developing an 'UserControl' derivated from textBox, because sequence event (and Validate event) seems to fail. I Always thought my code was wrong. But after...
0
by: Thorbjørn Jørgensen | last post by:
Hi I have a custom winform control based on UserControl. On this control I create some other controls in runtime. Tehse other controls contains RichTextBoxes. When I run the application I think my...
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...
0
by: BluDog | last post by:
Hi I have a vustom usercontrol that reacts by changing the background color when it receivess focus. However if i subsequently add another control to the usercontrol, that child control receives...
3
by: Simon Tamman | last post by:
I've come across an interesting bug. I have workarounds but i'd like to know the root of the problem. I've stripped it down into a short file and hope someone might have an idea about what's going...
2
by: Abhishek | last post by:
Hi I found lot of messages in this group on this issue but nothing actually explains it quite clearly. I've a user control with a text box and a list view. When i set the focus to the user...
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...
2
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hello experts, I posted a disturbing question in here:...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.