Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2011-09-14
9
Medium Priority
?
1,300 Views
Last Modified: 2013-12-14
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'
0
Comment
Question by:sydneyguy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 6

Accepted Solution

by:
effes earned 668 total points
ID: 36538799
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
 
LVL 16

Assisted Solution

by:SriVaddadi
SriVaddadi earned 668 total points
ID: 36538803
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
 
LVL 16

Expert Comment

by:SriVaddadi
ID: 36538830
You could create EventArgs like any other object
new EventArgs();

new MouseEventArgs() { Button=MouseButtons.Left,Location = new Point(33,10)}
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 664 total points
ID: 36538885
If you're not actually using the coords in the code then just use:

    btnConnect.PeformClick();
0
 

Author Comment

by:sydneyguy
ID: 36538980
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
 

Author Comment

by:sydneyguy
ID: 36538995
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
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 36539110
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
 
LVL 16

Expert Comment

by:SriVaddadi
ID: 36540044
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
 

Author Closing Comment

by:sydneyguy
ID: 36562279
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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question