C# private void btnConnect_Click(object sender, EventArgs e) calling a button generated function

I have a function that is run off a button on the form but wish to call it from another normal function were i do not have the mouse pos set up for the event e

private void btnConnect_Click(object sender, EventArgs e)

i can use
btnConnect_Click("contact", EventArgs e)
its looking for {X = 33 Y = 10 Button = Left}  System.EventArgs  System.Windows.Forms.MouseEventArgs}

but not sure how to recreate the EventArgs e varable that the function wants

Argument '2': cannot convert from 'string' to 'System.EventArgs'
sydneyguyAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
effesConnect With a Mentor Commented:
Hi sydneyguy,

just create antoher method that does the same thing the btnConnect_Click method does, but takes only the X- and Y-coordinates as input parameters (if that's all you need). You can then call this new method from inside the btnConnect_Click and wherever you want.

Hope that helps,
Frank
0
 
SriVaddadiConnect With a Mentor Commented:
why do you want  to call that event handler? Instead refactor the event handler code into a method and call that method in both event handler and you normal function  something like below

private void btnConnect_Click(object sender, EventArgs e)
{
    Connect();
}
private void Connect()
{
}
private void NormalMethod()
{
  Connect();
}

Does not work?
0
 
SriVaddadiCommented:
You could create EventArgs like any other object
new EventArgs();

new MouseEventArgs() { Button=MouseButtons.Left,Location = new Point(33,10)}
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Mike TomlinsonConnect With a Mentor Middle School Assistant TeacherCommented:
If you're not actually using the coords in the code then just use:

    btnConnect.PeformClick();
0
 
sydneyguyAuthor Commented:
the below code throws up the below errors

private void deleteemail_Click(object sender, EventArgs e)
        {
            new EventArgs();

            new MouseEventArgs() { Button=MouseButtons.Left,Location = new Point(33,10)}
        }

throws up  error shows
0
 
sydneyguyAuthor Commented:
I oftern run into this prop and woudl really like to get the artificial call going so that i do not have to re write code when an artificial call will do the perfect job
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Did you see my comment back here?
http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_27308500.html#36538885

Just use the PerformClick() method of the Button you want to click...
0
 
SriVaddadiCommented:
I suggested on how you could create EventArgs and MouseEventArgs. You cannot use the lines as is.

I agree with Idle_mind that you are better off using PerformClick() method of the button.

0
 
sydneyguyAuthor Commented:
thanks every one looking at your response i have used a variation on all three inputs, so awarded the points as such thanks for your help
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.