CS 0120:非静态字段、方法或属性“foo”需要对象引用考虑:namespace WindowsApplication1{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//int[] val = { 0, 0};
int val;
if (textBox1.Text == "")
{
MessageBox.Show("Input any no");
}
else
{
val = Convert.ToInt32(textBox1.Text);
Thread ot1 = new Thread(new ParameterizedThreadStart(SumData));
ot1.Start(val);
}
}
private static void ReadData(object state)
{
System.Windows.Forms.Application.Run();
}
void setTextboxText(int result)
{
if (this.InvokeRequired)
{
this.Invoke(new IntDelegate(SetTextboxTextSafe), new object[] { result }); }
else
{
SetTextboxTextSafe(result);
}
}
void SetTextboxTextSafe(int result)
{
label1.Text = result.ToString();
}
private static void SumData(object state)
{
int result;
//int[] icount = (int[])state;
int icount = (int)state;
for (int i = icount; i > 0; i--)
{
result += i;
System.Threading.Thread.Sleep(1000);
}
setTextboxText(result);
}
delegate void IntDelegate(int result);
private void button2_Click(object sender, EventArgs e)
{
Application.Exit();
}
}}为什么会发生此错误?非静态字段、方法或属性‘WindowsApplication1.Form1.setTextboxText(int)需要对象引用。
4 回答
Smart猫小萌
TA贡献1911条经验 获得超7个赞
SumData
SumData
SetTextboxText
SetTextboxText
.
牛魔王的故事
TA贡献1830条经验 获得超3个赞
static void setTextboxText(int result){ if (this.InvokeRequired) { this.Invoke(new IntDelegate(SetTextboxTextSafe), new object[] { result }); } else { SetTextboxTextSafe(result); }}
- 4 回答
- 0 关注
- 763 浏览
添加回答
举报
0/150
提交
取消