C# 有没有办法使用按钮发送器将文本(按钮上的)直接发送到列表框中
我尝试了两种解决方案,但都不起作用,第一种是直接将其发送到列表框,但都不起作用 1.将其直接发送到列表框中C# 有没有办法使用按钮发送器将文本(按钮上的)直接发送到列表框中,c#,C#,我尝试了两种解决方案,但都不起作用,第一种是直接将其发送到列表框,但都不起作用 1.将其直接发送到列表框中 private void button_Click(object sender, EventArgs e) { Button b = (Button)sender; lbItems = b.Text; } 2.我尝试的另一种方法是先将其发送到texbox,然后将字符串从texbox发送到listbox,但一个按钮后代码就会
private void button_Click(object sender, EventArgs e)
{
Button b = (Button)sender;
lbItems = b.Text;
}
2.我尝试的另一种方法是先将其发送到texbox,然后将字符串从texbox发送到listbox,但一个按钮后代码就会中断
private void button_Click(object sender, EventArgs e)
{
Button b = (Button)sender;
lbItems = b.Text;
if (txtPre.Text == " ")
{
}
else
{
lbItems.Items.Add(txtPre.Text);
txtPre.Clear();
}
}
lbItems.Items.Add(b.Text)代码>?lbItems=b.文本代码>是非法代码lbItems.Items.Add(b.Text)代码>?lbItems=b.文本代码>是非法代码
lbItems.Items.Add((sender as Button).Text);