Avoiding focus

  • Thread starter Thread starter Christopher Thompson
  • Start date Start date
C

Christopher Thompson

I'm building a virtual keyboard for a touch screen
application. When I hit a key on the keyboard, I lose
focus on my text box (or whatever I'm in at the time). If
I have a range of text selected, when I restore focus, I
lose the selected range. What I would like to do is avoid
losing the focus from the text box when I press a key on
my keyboard (which is implemented as a User Control). Is
there some way to do this? Or another workaround to
maintain the selected text range in the text box?

PS> I'm using C#.
 
You could use a series of controls that do not "steal" focus, like a Label.
So create each key as a Label control and then just change the backcolor
when the user selects the key. Or if you want to be even more daring then
you can write your own custom control and custom paint the keys as well as
handle the mouse clicks accordingly.
 
OK, that does work. I added labels to a User Control. But
now I need this Control to do a couple more things:
1) it need to 'float' like a toolbar, but support
multiple rows of keys (labels) like a keyboard;
2) it needs to always stay on top of any other
APPLICATION windows, not neccessarily windows from other
applications.
 
You need to look into creating a top level window to hold your keyboard. I
would recommend starting a new thread and asking your questions there.
 
Christopher,

You may try puting your usercontrol on a form and set the form topmost
property to true, you need also change the form style and add the
WS_EX_NOACTIVATE to prevent it getting focus. it could be done by
overriding the CreateParams property like below:
<code>
protected override CreateParams CreateParams
{
get
{
const int WS_EX_NOACTIVATE = 0x08000000;
CreateParams params = base.CreateParams;
params.ExStyle = params.ExStyle | WS_EX_NOACTIVATE;
return params;
}
}
</code>
Does it solve your problem?

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, "online" should be removed before
sending.
 
Back
Top