我想将列表框中的选定项目用作字符串。从 listBox1_SelectedIndexChanged 它工作正常。我如何在课堂上全局使用它?
我将它放在班级的顶部,并试图将其设为静态,但出现以下错误。有人可以告诉我如何参考吗?
错误 1 非静态字段、方法或属性需要对象引用
public class
{
static string listme = listBox1.GetItemText(listBox1_SelectedIndexChanged);
public Form1()
{
InitializeComponent();
this.Shown += new EventHandler(listBox1_SelectedIndexChanged);
}
public void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
listBox1.SelectedIndex = 0;
string items = listBox1.GetItemText(listBox1.SelectedItem);
MessageBox.Show(Backups + @"\" + items);
}