Access key on user control 
Author Message
 Access key on user control

Hi all,

I am creating a user control. So I inherited form the
UserControl class and designed my functionality.

I've only one problem. My control has as text property,
and I want if I set this property for example to '&Close',
that when the user presses alt+c, I get an event in my
control. Just like a normal button control in .net.

I hope this is possible!

Thanx,
Jan



Wed, 15 Jun 2005 19:51:52 GMT  
 Access key on user control
Hi Jan,
This is possible.

Make two new members in the UserControl :

public delegate void NewEventHandler(object sender, string str); //
public event NewEventHandler AltC;  // That is the event you will see when
you use the usercontrol somewhere.

Add a method in the UserControl which fires then the event AltC :

private void UserControl1_KeyDown(object sender,
System.Windows.Forms.KeyEventArgs e)

{

if (e.Alt && (e.KeyCode.ToString().ToLower() == "c") && (textproperty ==
"&Close")  ) // both must be true : alt c and ...

{

if (AltC != null)

{

AltC(this,"OK");

Quote:
}
}
}

Hope this helps.


Quote:
> Hi all,

> I am creating a user control. So I inherited form the
> UserControl class and designed my functionality.

> I've only one problem. My control has as text property,
> and I want if I set this property for example to '&Close',
> that when the user presses alt+c, I get an event in my
> control. Just like a normal button control in .net.

> I hope this is possible!

> Thanx,
> Jan



Wed, 15 Jun 2005 21:47:03 GMT  
 Access key on user control
Johan

Thanks, but I mean something else. When using your
solution the control only catches the alt+c keypress when
the control is focused. A normal button control, with the
&Close text property, catches the alt+c keypress when the
form where it is placed on, has the focus.

I could catch the keypress on the form, and then pass it
to my user control. But I want similar behaviour like the
standard controls.

Thanx
Jan

Quote:
>-----Original Message-----
>Hi Jan,
>This is possible.

>Make two new members in the UserControl :

>public delegate void NewEventHandler(object sender,
string str); //
>public event NewEventHandler AltC;  // That is the event
you will see when
>you use the usercontrol somewhere.

>Add a method in the UserControl which fires then the
event AltC :

>private void UserControl1_KeyDown(object sender,
>System.Windows.Forms.KeyEventArgs e)

>{

>if (e.Alt && (e.KeyCode.ToString().ToLower() == "c") &&
(textproperty ==
>"&Close")  ) // both must be true : alt c and ...

>{

>if (AltC != null)

>{

>AltC(this,"OK");

>}

>}

>}

>Hope this helps.



>> Hi all,

>> I am creating a user control. So I inherited form the
>> UserControl class and designed my functionality.

>> I've only one problem. My control has as text property,
>> and I want if I set this property for example
to '&Close',
>> that when the user presses alt+c, I get an event in my
>> control. Just like a normal button control in .net.

>> I hope this is possible!

>> Thanx,
>> Jan

>.



Wed, 15 Jun 2005 22:11:47 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Horrible user control bug stripped all user controls from my project

2. Access to Arrow keys in popup dialog in MFC ActiveX control / under VB

3. User Controls: Accessing Properties (a slightly different point of view)

4. Problem accessing user control element from javascript

5. user change or change user rights for MS ACCESS DB with DAO (MFC)

6. Accessing control panel applications without accessing control panel

7. Reading keys keys in a custom control

8. Accessing control array controls using the controls collection

9. Key Buffer Problem ATL Windows RichEdit Control Control

10. TAB key, controls and child windows with controls

11. how to send key event to other user application

12. C# Focus Issues - Touch Screen - User Controls - Button Control - TextBox

 

 
Powered by phpBB® Forum Software