bunifu

Visual Studio C# and Bunifu UI, can't find on click method


I'm sorry if the title is long, my problem is I added a button (From Bunifu framework) programmatically.

Here is the code:

Bunifu.Framework.UI.BunifuFlatButton Contact = new Bunifu.Framework.UI.BunifuFlatButton();
ContactsBox.Controls.Add(Contact);

Tho I need the onClick method, and I do not know how to get it.. Any help?


Solution

  • I hesitate to answer because the question is poorly worded and I'm not certain this is what you're looking for, but here's how to hook up a Click event to a control created in code:

    var button = new Bunifu.Framework.UI.BunifuFlatButton();
    button.Click += Button_Click;
    

    In Visual studio, after you type the +=, pressing Tab will create the click event template for you:

    private void Button_Click(object sender, EventArgs e)
    {
        throw new NotImplementedException();
    }
    

    Then you just replace the throw line with whatever code you want to execute when your button is clicked.

    An instance of the control whose event triggers this method is passed through the sender argument. A common way to get the instance inside the event is to check the type and cast it:

    if(sender is BunifuFlatButton)
    {
        var button = (BunifuFlatButton) sender;
        MessageBox.Show($"You clicked the button named '{button.Name}'");
    }