473,385 Members | 1,474 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Programmatically triggering a button from another form in C#

1
Good Afternoon

I have a button sitting on form1 and i would like form2 to trigger that button

How do I go about doing that:

eg say button1.PerformClick();

I would like to call the event using form2 and the button is on form1
Sep 25 '07 #1
5 2771
Plater
7,872 Expert 4TB
make the event handler public and then you can call myformA.Button1_Clicked(sender, eventargs).

Or, you might be able to trigger it through the messagepump. You could send a windows message of a mouseclick over and trick it. Although that's much more complicated.
Sep 25 '07 #2
r035198x
13,262 8TB
Good Afternoon

I have a button sitting on form1 and i would like form2 to trigger that button

How do I go about doing that:

eg say button1.PerformClick();

I would like to call the event using form2 and the button is on form1
Depends on the eventargs expected by the form1's action handler.
If you don't care about the event args, then you also consider declaring a method elsewhere which does the required actions and then you can just call that method from both action handlers of the two buttons.
Sep 25 '07 #3
Plater
7,872 Expert 4TB
EventArgs for most of the event handlers contain nothing usefull, especially if they're "EventArgs" and not say "MouseEventArgs".
And if you don't use what comes in on them, then it doesn't matter either way
Sep 25 '07 #4
r035198x
13,262 8TB
eventargs for most of the event handlers contain nothing usefull, especially if they "EventArgs" and not say "MouseEventArgs".
And if you don't use what comes in on them, then it doesn't matter either way
True. I just don't like the idea of calling an action handler in code. That's not good practice at all is a nice recipe for spaghetti.
Sep 25 '07 #5
Plater
7,872 Expert 4TB
True. I just don't like the idea of calling an action handler in code. That's not good practice at all is a nice recipe for spaghetti.
Me either, but they asked for it.
Generally I would have a function that my action handlers call, that other handlers/functions can have access to.
Sep 25 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: aundro | last post by:
Hello, I've been looking on the web for a solution to this problem: I create a set of checkboxes, and 2 buttons: - one is labeled "All" - the other is labeled "None" Clicking "All" is...
5
by: Carlo Marchesoni | last post by:
From an aspx page (A.aspx) I open another one (B.aspx - for table lookup). When the user selects an entry in B.aspx I would like to force a button's event in A.aspx to be fired. I guess the only...
8
by: Steve Schroeder | last post by:
For some reason I cannot get the OnSelectedIndexChanged event to fire for a listbox I have on a page. I'm able to populate the listbox with data from a stored procedure, but cannot trigger the...
15
by: Oleg Subachev | last post by:
I need to programmatically invoke from other class Click event of the Button on my Form. Button.OnClick method is protected, not public. How to perform this ? Oleg Subachev
8
by: mark.norgate | last post by:
I've asked this question before, but still haven't solved it, so am asking again. I am programmatically adding a user control to the page in response to a button click. The user control consists...
2
by: Jason | last post by:
Is there any way to initiate a sqldatasource insert from code in place of the button with commandname=insert or insert? I have a formview with a datasource with an insert command on a button....
8
by: =?Utf-8?B?UmljaA==?= | last post by:
My from contains a "Move Next" button. When the user clicks on the "Move Next" button - several procedures get invoked and eventually, the dataset underlying the form will display main data from...
2
by: ChrisCicc | last post by:
Hi All, I got a real doozy here. I have read hundreds upon hundreds of forum posts and found numerous others who have replicated this problem, but have yet to find a solution. Through testing I have...
0
by: Tom | last post by:
The included code block demonstrates programmatically clicking a non-derived ToolStripButton in the OnShown() method. When I derive a button from ToolStripButton and override the _private_...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.