How to Generate a button click event programatically

G

Guest

Hi,
I am developing an Pocket PC 2002 Application on .net cf 1.0 with Service
pack 2.

I want to click a button programatically on pressing a key.

Can Some one tell me if it can be done in .net cf and if so how i can do it.

Thanks in Advance,
Murthy
 
L

Lonifasiko

Hi,

If you double click a button, automatically some code is generated for
you. That would be the event executed after the button is pressed.
Instead of double clicking the button in the "Designer" View, you could
also add manually the eventhandler for the button:

// Assign the eventhandler to the button
this.button1.Click += new System.EventHandler(this.button1_Click);

// Code executed when button is pressed
private void button1_Click(object sender, EventArgs e)
{
// Whatever you want to do
}

In your key press event (CF 1.0 gives you access to hardware keys?),
you can call this event like this:

button1_Click(this, EventArgs.Empty);
button1_Click(this, new EventArgs());
button1_Click(null, new EventArgs());

I adviseyou to upgrade at least to CF 1.0 Service Pack 3. Using CF 2.0
with Visual Studio 2005 would be much easier for you.

Hope it helps.
 
G

Guest

Thanks for your reply.
But what i am looking for is the occurance of Click Event on the button.

I want it to be no different from Pressing the Button directly.
I want the Button to be pressed.

Thanks again....
Waiting for your reponse...
 
L

Lonifasiko

Sorry but I think I don't understand you correctly.

You've got a button and you want to execute some code when the button
has focus and a key is pressed, not clicked?

Maybe this can help you?

button1.Focus();
button1.KeyPress += new KeyPressEventHandler(button1_KeyPress); // Or
redirect to whatever method/event you want

void button1_KeyPress(object sender, KeyPressEventArgs e)
{
MessageBox.Show("HELLO!");
}

I understand this. See if this helps you. Else, tell me again a little
more in detail.

Regards.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top