Click here to Skip to main content
15,913,584 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
This is my class code

C#
public void Createlabel()
   {
       Label intervillabel = new Label();
       intervillabel.Text = numericUpDown1.Value.ToString();
       intervillabel.Location = new Point(BeatDetector.Location.X, 0);
       intervillabel.AutoSize = true;
       intervillabel.Visible = true;

       panel1.Controls.Add(intervillabel);

   }


and I want that label to be created when I do this

C#
private void Form1_KeyDown(object sender, KeyEventArgs e)
    {
             if (e.KeyCode == Keys.ControlKey)
        {
// this is where the label will be added to the panel1

//for example, onlt this code should be here

// panel1.Controls.Add(intervillabel)
}

}

this is what I want to happen. When I press the key on the form the button will be created on that posion but my problem is, is that idk how to make it so it will make a button there hen I press it, all I have is this class that I don't know how to use that well
Posted
Comments
Mantu Singh 4-May-12 6:25am    
pls be more clear.....

1 solution

C#
public Label Createlabel()
   {
       Label intervillabel = new Label();
       intervillabel.Text = numericUpDown1.Value.ToString();
       intervillabel.Location = new Point(BeatDetector.Location.X, 0);
       intervillabel.AutoSize = true;
       intervillabel.Visible = true;
 return intervillabel;
      // panel1.Controls.Add(intervillabel);
 
   }

private void Form1_KeyDown(object sender, KeyEventArgs e)
    {
             if (e.KeyCode == Keys.ControlKey)
        {
              panel1.Controls.Add(Createlabel())
        }
 
    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900