gpt4 book ai didi

c# - 无法访问 listBox1

转载 作者:太空宇宙 更新时间:2023-11-03 17:21:28 25 4
gpt4 key购买 nike

我有 listBox1,但是当我在 buttonClick 内部使用 listBox1 时,我可以访问但在 buttonClick 外部我无法访问。我哪里做错了?谢谢

namespace design
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button4_Click(object sender, EventArgs e)
{
listBox1.Items.Add(button1.Text);// I can access listBox1 here...
}

listBox1.//I can't access listBox1 here....
}
}

最佳答案

可以在那里访问它,但它不起作用,因为您不在任何函数或方法中。

你不能只是在类中的某处开始键入代码,你需要处理某种事件或其他事情。

顺便说一句,这是非常基本的 C# 知识。

关于c# - 无法访问 listBox1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11542451/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com