shah Momin

shah Momin

  • NA
  • 176
  • 22.2k

How To Make Dynamic Button With Text OR Number

Jul 9 2022 8:35 AM
private void BtnNewDutySpot_Click(object sender, EventArgs e)
{
    int Count = 1;

    string str1 = "Reserved";
    int MaxLimit = 0;

    try
    {
        Button btn = new Button() ;
        Count += 1;
        btn.Dock = DockStyle.Fill;
        btn.Name = "Reserved" + Count;
        btn.Text = "Reserved" +  Environment.NewLine + MaxLimit;
        btn.BackColor = System.Drawing.Color.FromArgb(48, 56, 67);
        btn.ForeColor = Color.White;
        tblDutySpot.Controls.Add(btn);
        btn.Click += new System.EventHandler(btn_Click);
    }
    catch(Exception ex)
    {
        int num3 = (int)bunifuSnackbar1.Show(this, ex.Message, Bunifu.UI.WinForms.BunifuSnackbar.MessageTypes.Error, 3000, "X");

    }
}

private void btn_Click(object sender,EventArgs e)
{
    Button btn = (Button)sender;
    txtSpotName.Text = btn.Name;
    numMaxLimit.Text = btn.Text;

}

 


Answers (3)