`我想要在靜態方法中更改文本框文本。我怎麼能這樣做,考慮到我不能在靜態方法中使用「this」關鍵字。換句話說,我怎樣才能使一個對象引用文本框的文本屬性?非靜態字段,方法或屬性'member'需要對象引用
這是我的代碼
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public delegate void myeventhandler(string newValue);
public class EventExample
{
private string thevalue;
public event myeventhandler valuechanged;
public string val
{
set
{
this.thevalue = value;
this.valuechanged(thevalue);
}
}
}
static void func(string[] args)
{
EventExample myevt = new EventExample();
myevt.valuechanged += new myeventhandler(last);
myevt.val = result;
}
public delegate string buttonget(int x);
public static buttonget intostring = factory;
public static string factory(int x)
{
string inst = x.ToString();
return inst;
}
public static string result = intostring(1);
static void last(string newvalue)
{
Form1.textBox1.Text = result; // here is the problem it says it needs an object reference
}
private void button1_Click(object sender, EventArgs e)
{
intostring(1);
}`
請向我們展示您正在使用的代碼。 – 2013-03-09 22:32:02