C# 单击FlowLayoutPanel中的事件
我在Visual Studio 2013 c#winform中编程。是否可以为FLP中的每个按钮选择单击事件?我试着做一些像蒸汽图书馆的事情,我已经做了很多事情,现在看起来我想做 (抱歉,我无法添加图像) 但我不知道当你们点击FLP(在库中)中的一个按钮时,如何打开选中的游戏。 这就是我的代码的外观:C# 单击FlowLayoutPanel中的事件,c#,winforms,visual-studio,C#,Winforms,Visual Studio,我在Visual Studio 2013 c#winform中编程。是否可以为FLP中的每个按钮选择单击事件?我试着做一些像蒸汽图书馆的事情,我已经做了很多事情,现在看起来我想做 (抱歉,我无法添加图像) 但我不知道当你们点击FLP(在库中)中的一个按钮时,如何打开选中的游戏。 这就是我的代码的外观: private void btnTest_Click_1(object sender, EventArgs e) { if (textBox1.Text != "")
private void btnTest_Click_1(object sender, EventArgs e)
{
if (textBox1.Text != "")
{
if (textBox2.Text != "")
{
Button btn = sender as Button;
Button btnNew = new Button();
btnNew.Text = "";
btnNew.Height = 108;
btnNew.Width = 230;
btnNew.Image = new Bitmap(textBox1.Text);
btnNew.FlatStyle = FlatStyle.Flat;
flpContainer.Controls.Add(btnNew);
btnNew.Click += btnNew_Click;
counter1++;
label1.Text = counter1.ToString(); //label1 is that "Number of games in library:"
System.Windows.Forms.MessageBox.Show("Game was succesfully added to library!");
}
else if (textBox2.Text == "")
{
System.Windows.Forms.MessageBox.Show("You didn't choosed exe file!");
}
}
if (textBox1.Text =="")
{
System.Windows.Forms.MessageBox.Show("You didn't choosed image!");
}
}
private void btnNew_Click(object sender, EventArgs e)
{
Process.Start(textBox2.Text); //textbox2 is the path to exe file, but it change when you want to add another game to library
}
但是如何为FlowLayoutPanel中的每个按钮执行不同的单击事件呢?
谢谢你的回答
编辑:我想这样做,当你们点击库中的一个按钮时,它会打开那个游戏(程序)
多谢各位 将所需信息存储在
标记中
属性以备将来使用,并完成工作
Button btnNew = new Button();
btnNew.Text = "";
btnNew.Height = 108;
btnNew.Width = 230;
btnNew.Image = new Bitmap(textBox1.Text);
btnNew.FlatStyle = FlatStyle.Flat;
flpContainer.Controls.Add(btnNew);
btnNew.Click += btnNew_Click;
btnNew.Tag = textBox2.Text;// <--Store it in Tag
将你的图片上传到一些好的网站,例如:Tinypic.com或Imgur.com,我无法查看你链接中的图片。答案取决于你在点击事件中想做什么。举一些具体的例子
private void btnNew_Click(object sender, EventArgs e)
{
Button clickedButton = (Button)sender;
Process.Start((string)clickedButton.Tag);
}