Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 14th, 2004, 05:23 AM
Authorized User
 
Join Date: Jun 2003
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default Can't get focus on user control

Hi all,
I'm trying to write a text editor for a mobile device that can support different coloured text.

So far everything is going well, but the form won't accept the keydown event, i.e. its never fired (the breakpoint is never reached)
Whenever the user clicks the mouse on the control I use the following code:

            if(this.CanFocus)
                if(!this.Focus())
                    MessageBox.Show("No Focus");

It always brings up the message box. It must be able to get focus though. Does anyone know why it won't get focus.

Cheers
DRB2k2
 
Old December 14th, 2004, 07:46 PM
Kep Kep is offline
Authorized User
 
Join Date: Aug 2003
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If we're talking about Windows Forms...

You could try setting Form.KeyPreview = true. When this property is true the form receives all keyboard events before they are sent to controls.

As to why the form never receives focus, I not sure without more info, it maybe because there is another control on the form and this control has the input focus.

Hope it helps.

Kep.
 
Old December 15th, 2004, 12:51 PM
Authorized User
 
Join Date: Jun 2003
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Kep,
That worked fine, but I see that mobile forms don't have a key preview property. Oh well bang goes my idea of developing a control for compact.net and regular .net.

Cheers
DRB2k2





Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't move focus to control <control scptech Access VBA 8 October 26th, 2007 12:16 PM
USER CONTROL FOCUS PROBLME ......PLZ. HELP ME meerraj ASP.NET 1.0 and 1.1 Professional 1 February 28th, 2007 06:29 AM
Add Windows User control in Web User Control agarwalvidhu C# 0 March 30th, 2006 01:17 AM
Set Focus to Field in User Control Ron Howerton ASP.NET 1.0 and 1.1 Professional 3 March 14th, 2006 05:53 PM
Control Focus of Page mahulda General .NET 1 July 23rd, 2004 08:52 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.