[C#] Problem on button click

Discussion in 'Mixed Languages' started by carmz, Aug 12, 2012.

  1. carmz

    carmz MDL Senior Member

    Nov 29, 2011
    285
    7
    10
    #1 carmz, Aug 12, 2012
    Last edited: Aug 14, 2012
    [SOLVED][C#] Problem on button click

    Hi, can i ask some help on you guys,i have no idea how to put Event handler on my Button using code.

    can you help me on this please.

    thank you in advance.
     
  2. BobSheep

    BobSheep MDL Guru

    Apr 19, 2010
    2,326
    1,358
    90
    In form designer, double click the button.
     
  3. carmz

    carmz MDL Senior Member

    Nov 29, 2011
    285
    7
    10
    But i am doing this during run time...here is my code

    I want to put Event handler on mybtn Button...can you help me please...

    By the way Bob why is that when i am going to reply or post new thread the text of all buttons is invisible here , i find difficulties to reply and to attach...
     
  4. Josh Cell

    Josh Cell MDL Developer

    Jan 8, 2011
    3,519
    7,103
    120
    #4 Josh Cell, Aug 12, 2012
    Last edited by a moderator: Apr 20, 2017
    Code:
    private void button1_Click(object sender, EventArgs e)
    {
         Button mybtn = new Button();
         mybtn.Text = "Hello";
         mybtn.Click  += new EventHandler(mybtnClick);
    }
    
    void mybtnClick(object sender, EventArgs e)
    {
         MessageBox.Show("mybtn was clicked.");
    }
    But no drawn for the button.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. carmz

    carmz MDL Senior Member

    Nov 29, 2011
    285
    7
    10
    #5 carmz, Aug 13, 2012
    Last edited: Aug 14, 2012
    (OP)
    [solved]

    Hi josh,thank you for this,it's working
     
  6. QuantumBug

    QuantumBug MDL Developer

    Mar 7, 2012
    1,488
    1,327
    60
    Edit Post > Advanced > [SOLVED]

    :D
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...