So I have the following code for when the "Add player" button is clicked
private void addPlayerBtn_Click_1(object sender, EventArgs e)
{
//Do some code
}
I want to trigger this code from my SDK however. Here is what I have tried
private void command()
{
addPlayerBtn_Click_1(object sender, EventArgs e);
}
I get lots of errors as soon as I put in the line
addPlayerBtn_Click_1(object sender, EventArgs e)
Could somebody please tell me how to write the code so that I can trigger an event by just writting it in code?
To trigger a click button on ENTER key, We can use any of the keyup(), keydown() and keypress() events of jQuery. keyup(): This event occurs when a keyboard key is released. The method either triggers the keyup event, or to run a function when a keyup event occurs.
Button event is always trigger when you click the button but if you want to raise your button click event manually from code then you can use Button. PerformClick() from your code. Suppose on click of your Button1 you want to trigger Button2 click event then Please refer this[^] MSDN example.
gameObject. GetComponent<Button>(). Click();
For one, when calling a method, you don't declare the type of the parameter, just the value.
So this:
addPlayerBtn_Click_1(object sender, EventArgs e);
Should be
addPlayerBtn_Click_1(sender, e);
Now, you'll have to declare sender
and e
. These can be actual objects, if you have event args to pass, or:
addPlayerBtn_Click_1(null, EventArgs.Empty);
The above can be used in either WinForms or ASP.NET. In the case of WinForms, you can also call:
addPlayerBtn.PerformClick();
When you call a function, you provide actual arguments, which are values, not formal arguments, which are types and parameter names.
Change
addPlayerBtn_Click_1(object sender, EventArgs e);
to
addPlayerBtn_Click_1(addPlayerBtn, EventArgs.Empty);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With