Search code examples
c#winformsdevexpresssimplebutton

How Make a button dynamically?


I'm doing a "list" of buttons, like a Menu in a Form, and I'm trying to do it out of a table in a database, I'm doing this like this:

foreach (Catalogos catalogo in catalogos)
{
    SimpleButton sb = new SimpleButton();
    sb.Text = catalogo.Nombre;
    sb.Click += catalogo.Evento;
    LayoutControlItem item = new LayoutControlItem();
    item.TextVisible = false;
    item.Control = sb;
    lcg.Add(item);
 }

My problem is in the sb.Click += catalogo.Evento line, how can I do the eventy dynamically


Solution

  • Use a lambda / anonymous method

    SimpleButton sb = new SimpleButton();
    sb.Text = catalogo.Nombre;
    sb.Click += (sender, evntArgs) => {
        //some dynamic mouse click handler here.
    };