Hello,
根据你的描述, 你是想点击ListBox item, 然后显示对应的被隐藏的Button, 我建议你可以在ListBox_MouseClick event 里来实现这个。
public Form6()
{
InitializeComponent();
}
private void Form6_Load(object sender, EventArgs e)
{
listBox1.Items.Add("test1");
listBox1.Items.Add("test2");
listBox1.Items.Add("test3");
listBox1.Items.Add("test4");
test1.Visible = false;
test2.Visible = false;
test3.Visible = false;
}
private void listBox1_MouseClick(object sender, MouseEventArgs e)
{
int index = listBox1.IndexFromPoint(e.X, e.Y);
listBox1.SelectedIndex = index;
if (listBox1.SelectedIndex != -1)
{
MessageBox.Show(listBox1.SelectedItem.ToString());
string selectitem = listBox1.SelectedItem.ToString();
displaybtn(selectitem);
}
}
private void displaybtn(string btnname)
{
foreach(Control c in this.Controls)
{
if(c is Button )
{
if(c.Name==btnname)
{
c.Visible = true;
}
}
else
{
return;
}
}
}

Best Regards,
Cherry
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to
MSDN Support, feel free to contact MSDNFSF@microsoft.com.