C#类多数民众赞成在按下按钮时将要创建的对象 [英] C# classes thats make object that will be then made when a button is pressed
本文介绍了C#类多数民众赞成在按下按钮时将要创建的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的课程代码
This is my class code
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
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)
}
}
这就是我想发生的事情.当我按下表单上的键时,将在该位置上创建按钮,但是我的问题是,idk如何制作它,以便在按下该按钮时在该位置创建一个按钮,我所拥有的只是我所没有的此类
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
推荐答案
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())
}
}
这篇关于C#类多数民众赞成在按下按钮时将要创建的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文