0
private void btnSend_Click(object sender, EventArgs e)
{
    Dosomething();
}

private void Something(object sender, EventArgs e)
{
    btnSend_click( how to write in here?? )
}

I want to implement btnSend_Click in other section(?), but i don't know how to do this. i want to implement this code without using UI.

1

2 Answers 2

1

If you just need to call the method btnSend_Click from the method Something, you can pick any of these:

private void Something(object sender, EventArgs e)
{
    btnSend_click(this, EventArgs.Empty);
}

Or

private void Something(object sender, EventArgs e)
{
    btnSend_click(sender, e);
}
Sign up to request clarification or add additional context in comments.

Comments

1

It is all about naming, that is, giving the methods a good name.

First, you write the underlying method that does the actual work.

public class Someone 
{
    public void DoSomething()
    {
        Console.Beep(); //make a noise
    }
}

At this point, no UI is involved, no button, no sender, no EventArgs.

Then

Call this method when the button is clicked.

private void btnSend_Click(object sender, EventArgs e)
{
    new Someone().DoSomething();
}

Call this method from any other place.

class AnotherOne 
{
    private void DoAnotherThing()
    {
        new Someone().DoSomething();     
    }
}  

I don't answer your question on how to call btnSend_click from anywhere by passing faked sender and EventArgs.

Because that is not a good idea to write such calls - before long you will be confused by the names even if the code was written by yourself.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.