Hi,

I have a Form with a panel which has multiple Text Box Components.

I'm trying to find a way for the user to jump between the Text Boxes
without using a mouse, or more simplisticly, jump to the next Text Box.

Other posts (Google link below) suggest there isn't a built in way to
capture tab-press events, so I have tried the following:

private void txtNameFirstName_TextChanged(object sender,
System.Windows.Forms.KeyPressEventArgs e)
{
if (e.KeyChar == 13)
{
txtNameLastName.Focus();
}
}

How do I get this method to be actioned on the event "_TextChanged". I
guess a more generic question is how can I assign a method to an event?

Regards,

Joe.



http://groups.google.co.uk/group/microsoft.public.dotnet.framework.compactframework/browse_frm/thread/bed5c0fea67018a5/bcc28ce73d5d3976?q=text+box+event+tab&rnum=2&hl=en#bcc28ce73d5d3976

Re: Howto assign a method to an event by ctacke/>

ctacke/>
Sun Aug 21 22:13:36 CDT 2005

1. TabOrder is the same as Z-Order and works of SP1 (or 2?) on.
2. Using an app wide IMessageFilter would probably work better at
implementing what you're after
3. A Tab is ascii 9, not 13
4. Adding an eventhandler is done with a +=, like txtMyTextbox.OnChange +=
new EventHandler(MyHandler);

-Chris


"Joe" <joe.williams@hotmail.co.uk> wrote in message
news:1124648180.760496.21560@g14g2000cwa.googlegroups.com...
> Hi,
>
> I have a Form with a panel which has multiple Text Box Components.
>
> I'm trying to find a way for the user to jump between the Text Boxes
> without using a mouse, or more simplisticly, jump to the next Text Box.
>
> Other posts (Google link below) suggest there isn't a built in way to
> capture tab-press events, so I have tried the following:
>
> private void txtNameFirstName_TextChanged(object sender,
> System.Windows.Forms.KeyPressEventArgs e)
> {
> if (e.KeyChar == 13)
> {
> txtNameLastName.Focus();
> }
> }
>
> How do I get this method to be actioned on the event "_TextChanged". I
> guess a more generic question is how can I assign a method to an event?
>
> Regards,
>
> Joe.
>
>
>
> http://groups.google.co.uk/group/microsoft.public.dotnet.framework.compactframework/browse_frm/thread/bed5c0fea67018a5/bcc28ce73d5d3976?q=text+box+event+tab&rnum=2&hl=en#bcc28ce73d5d3976
>



Re: Howto assign a method to an event by Joe

Joe
Mon Aug 22 04:02:41 CDT 2005

Thank you, I'll have a read about Z-order and IMessageFilter.

I have tried using the event handler but get this error:

SmartDeviceApplication3\FormMain.cs(265): Method
'SmartDeviceApplication3.frmMain.txtNameFirstName_KeyPress(object,
System.Windows.Forms.KeyPressEventArgs)' does not match delegate 'void
System.EventHandler(object, System.EventArgs)'

I add the event handler with:

this.txtNameFirstName += new
System.EventHandler(this.txtNameFirstName_KeyPress);

And the event method is:

private void txtNameFirstName_KeyPress(object sender,
System.Windows.Forms.KeyPressEventArgs e)
{
MessageBox.Show("OK");
}

Some examples use 'public event MyEvent' - but I notice none of the
Designer generated events seem to require this.

Does the error mean that I am passing the wrong parameters to the event
handler, compared to how I am adding the event?

Regards,

Joe.


Re: Howto assign a method to an event by Chris

Chris
Mon Aug 22 09:22:18 CDT 2005

> I have tried using the event handler but get this error:
>
> SmartDeviceApplication3\FormMain.cs(265): Method
> 'SmartDeviceApplication3.frmMain.txtNameFirstName_KeyPress(object,
> System.Windows.Forms.KeyPressEventArgs)' does not match delegate 'void
> System.EventHandler(object, System.EventArgs)'

Exactly - and it's telling you the problem. You're using a method that has
(object, EventArgs) as parameters, but a KeyPress handler must take (object,
KeyPressEventArgs)

>
> I add the event handler with:
>
> this.txtNameFirstName += new
> System.EventHandler(this.txtNameFirstName_KeyPress);
>

You have to add the handler to an event, not an object, something like:

txtNameFirstName.KeyPress += ....

> Some examples use 'public event MyEvent' - but I notice none of the
> Designer generated events seem to require this.

You don't declare an event to consume one, only to expose one.

>
> Does the error mean that I am passing the wrong parameters to the event
> handler, compared to how I am adding the event?

See above.