473,324 Members | 2,239 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,324 software developers and data experts.

Not clicking to use a button click

4
Hi there. I need to simulate a button's method (say button2_click) by clicking button 1. what actually needs to happen is when i click button_1, if a check is passed, a method outside the button1_click must performs the button2_click method. I'm a bit of a beginner and I've bn hunting the net for ages now but to no avail.
any help would be appreciated
Apr 16 '09 #1
7 1837
Bassem
344 100+
Did you mean that:
Expand|Select|Wrap|Line Numbers
  1.         private void button1_Click(object sender, EventArgs e)
  2.         {   // anything to do... .
  3.             button2_Click(sender, e);
  4.             // anything to do... .
  5.         }
  6.  
  7.         private void button2_Click(object sender, EventArgs e)
  8.         {
  9.             // anything to do... .
  10.         }
  11.  
Apr 16 '09 #2
sliqer
4
Hi that isnt quite what I'm looking for.I nd it to access an external method.im not sure if it can be done.
something like this:
Expand|Select|Wrap|Line Numbers
  1. private void button1_Click(object sender, EventArgs e) 
  2. {   // anything to do... . 
  3.  
  4.     externalMethod()
  5.     // anything to do... . 
  6.  
  7. void externalMethod()
  8. {
  9.     //somehow perform this....
  10.     button2_Click(sender, e); 
  11. }      
  12.  
  13. private void button2_Click(object sender, EventArgs e) 
  14.      // anything to do... . 
  15. }
  16.  
Apr 16 '09 #3
tlhintoq
3,525 Expert 2GB
By "outside method" are you saying you want your program to click the button of a different program? You want to fool the other program into thinking a human clicked it's button?
Apr 16 '09 #4
sliqer
4
no no i think that would be a little beyond me :D. i just want to know how to use a click method in a second,different method (which isnt itself a click method).so i want to be able to run a method, that as part of its code, performs the click method of a button but the 2 methods are in the same program.i hope that makes it a bit clearer
Apr 16 '09 #5
tlhintoq
3,525 Expert 2GB
Really the best thing to do is to not code that way.

Write a method that performs the action you need.
Have the Click event call that method.
Have your second method call that method.

Expand|Select|Wrap|Line Numbers
  1. Public void  myButton_Click(object sender, eventargs e)
  2. {
  3.     SaveFile();
  4. }
  5.  
  6. public void CompletlyDifferentMethod()
  7. {
  8.      SaveFile();
  9. }
  10. private void SaveFile()
  11. {
  12.    // This is the Saving method
  13. }

But... If you insist on putting the meat of your code in the button click method and want to call it...

Expand|Select|Wrap|Line Numbers
  1. myButton_Click(this, eventargs.empty);
... will usually do the trick.

All the button click does is call a method with two parameters: An object and an eventargs. You are going to do the same this. You send it an object (usually 'this' or 'null' will due) and an eventargs.
Apr 16 '09 #6
sliqer
4
ok thanks so much.this seems to be doing the trick.i think the problem is i normally just get a bee in my bonnet and sit down and start typing.i spose i could plan a bit more! thx again
Apr 16 '09 #7
tlhintoq
3,525 Expert 2GB
@sliqer
Planning ahead is more than just good: It's vital. A novelist doesn't start writting at page 1; he creates a storyline, an outline, works out the story arc from beginning to end, marks major events, then fills out the characters and details.

Do you want to be whacker... or a Software Engineer that actually engineers his software?
Apr 17 '09 #8

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

Similar topics

10
by: sling blade | last post by:
Hello, I have an image map of a subdivision and each section of land in the subdivision has a lot number on it. Below the image map I have a table with details about each lot (eg Lot Number, Lot...
10
by: Jim Bayers | last post by:
We need to stop students from clicking on the form button more than once. We have a form that students fill out with their credit card information. They click, the form sends the data in xml to...
2
by: 23s | last post by:
My site's login page has a form w/ 2 textboxes and a submit button. If I'm in either of those textboxes (i.e., either one of the textboxes has focus), in any given browser, hitting "enter" on my...
6
by: pmud | last post by:
Hi, I have created a very simple ASP.NET application which has a couple of ImageButtons which go to different SQL reports on clicking them. I have used Response.Redirect to send the user to the ...
2
by: ljlolel | last post by:
I'm posting this again because I did not explain myself well the first time, so the problem was not being addressed. I made the following page (...
5
by: visu | last post by:
Hi this is a question asked in this group two years back.. No answer for this question till date. now i am in the same situation of the questioner.. to find a solution for this problem. Can any...
5
by: Alex | last post by:
Hello, I hope I can explain this properly. I'm writing an application with a tabbed-based navigation, and a form which gets filled out by users will be split into 5 subtabs. What I need is...
6
by: Paul Furman | last post by:
I'm getting incorrect response when hitting the enter key instead of actually clicking the button on a form. It activates but the post data isn't being sent I think. The php generated page...
4
by: munibe | last post by:
Hi, i have a problem about picturebox control. if you may help me, i will be so happy. i have a picturebox named pic_map, and i added a button named customer_button, my wish is to add a new small...
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: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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...

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.