473,566 Members | 2,785 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Simulate an event

On a form I would like to simulate a button click when the Enter is pressed.
My form is setup and it works if the delegate for the key pressed on the form
calls the delegate for the button pressed. But can we simulate a button click
instead?
This way if later the delegate is changed for the button, we don't forget to
do the changes on other events?
Nov 16 '05 #1
4 5166
"johnny" <jo****@discuss ions.microsoft. com> wrote in message
news:7C******** *************** ***********@mic rosoft.com...
On a form I would like to simulate a button click when the Enter is pressed. My form is setup and it works if the delegate for the key pressed on the form calls the delegate for the button pressed. But can we simulate a button click instead?
This way if later the delegate is changed for the button, we don't forget to do the changes on other events?


You can put the code you want to run in a function and call it from where
ever you need to, you don't need to "simulate" a button click. But you would
be better off just setting the button as the default button.

--
Michael Culley
Nov 16 '05 #2
The form (winform) supports a property AcceptButton. You can access it via
the properties window in the designer. You can set the acceptbutton to be
anyu button on the form. Whe enter is pressed, it will click that button.

If you phsically want to simultate a mouse click on your button, try looking
into
SendInput (Win32 not .NET) and use PInvoke.

Hope this helps!

Tom Wisnowski
MCP MCAD
"johnny" wrote:
On a form I would like to simulate a button click when the Enter is pressed.
My form is setup and it works if the delegate for the key pressed on the form
calls the delegate for the button pressed. But can we simulate a button click
instead?
This way if later the delegate is changed for the button, we don't forget to
do the changes on other events?

Nov 16 '05 #3

"johnny" <jo****@discuss ions.microsoft. com> wrote in message
news:7C******** *************** ***********@mic rosoft.com...
On a form I would like to simulate a button click when the Enter is pressed. My form is setup and it works if the delegate for the key pressed on the form calls the delegate for the button pressed. But can we simulate a button click instead?
This way if later the delegate is changed for the button, we don't forget to do the changes on other events?


In addition to the other replies, there is a method 'PerformClick' on
Button.

I think the AcceptButton property (as Tom mentioned) is your best bet for
the enter key, however.

Stu
Nov 16 '05 #4
Hi johnny,

Especially for Click (and couple of others) Control class has method for
simulating it.
Take a look at Control.InvokeO nClick method.

So what you need to do is to call your form's InvokeOnClick(b utton,
EventArgs.Emty) ;

where button is reference to the button which click event you want to raise.
--
HTH
Stoitcho Goutsev (100) [C# MVP]
"johnny" <jo****@discuss ions.microsoft. com> wrote in message
news:7C******** *************** ***********@mic rosoft.com...
On a form I would like to simulate a button click when the Enter is
pressed.
My form is setup and it works if the delegate for the key pressed on the
form
calls the delegate for the button pressed. But can we simulate a button
click
instead?
This way if later the delegate is changed for the button, we don't forget
to
do the changes on other events?

Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3267
by: Luis Faisco | last post by:
Hi, my problem may be trivial but I have been searching for an answer to this on the web without success. Hope you can help. This is the scenario: I am making a wizard composed of several steps, each step being a form with the post method. The first steps may be completed whether the user is logged on to the website or not. But from a...
2
1789
by: Amir Eshterayeh | last post by:
simulate virtual directory for each user Dear Friends Would you please give me your professional idea about this asp.net problem. I need different virtual directory for different customer with their names like these: www.oursite.com/Jack www.oursite.com/Sue
1
1877
by: charliewest | last post by:
I am trying use server controls or web controls to simulate the following behavior. I've an image wrapped w/in a link to create a rollover effect as if both elements we're one graphic: <a href="javascript:submit();" onMouseOver="MM_swapImage('Image1221','','images/btn_green_on.gif',1)" onMouseOut="MM_swapImgRestore()" id="A1"...
3
3052
by: Maileen | last post by:
Hi, I would like to know how to simulate an event in VB.NET ? in fact, for example when user press enter in some special textbox, i would like to raise a listview column click (for example). Moreover, how to tell VB.NET that : if user click on a button1, it is not the default button1_click() method to execute, but another method...and...
2
3476
by: Ryan Liu | last post by:
Can someone give a sample to prevent a row from being deleted in a datatable? I tried e.Row.RejectChanges(); in dt_RowDeleting() but seems does not work. I need verify if there other data using data in this row before actually remove it from datagrid. I can certainly control with Delete button. But if I want to allow the user to use...
8
2657
by: Doug Marquardt | last post by:
Hi All: I want to simulate VB6 Autoredraw in VB.Net I figure I would probably have to create a memory dc, paint to that, and then create a bitmap based on the dc and copy that image into a bitmap, and then assign that to the image property of my control? If so, then can someone push me in the right direction
1
1456
by: melton9 | last post by:
I've been searching around and haven't really found anything. I've but an IE browser on my form and would like to simulate clicking the provided refresh button on a one minute interval. I can't use navigate because the page has frames and only one frame does the refreshing. Surely theres a simple way to make the browser simulate the onclick...
6
2808
by: Charles Law | last post by:
I have a base class and derived classes that relate to a set of documents I process. e.g. DocBase, DocA, DocB, DocC. The processing of each document is handled in teh derived classes, as you might imagine, but the base class has properties and methods that are common to all documents. The processing of each docuemnt can result in a range of...
0
8108
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7644
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6260
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2083
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1201
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
925
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.