2013-03-17 57 views
0

在我的代码中,我有一个buttontextbox。我想通过点击button,将变量k的值发送到textbox。但是当我点击按钮时,什么都没有发生,我的代码有什么问题。 这是我的代码。使用事件传递参数

public partial class Form1 : Form 
    { 
     public Form1() 
     { 
      InitializeComponent(); 
     } 
     public delegate string fac(int x); 
     public static fac intostring = factory; 

     public static string inst= null; 
     public static string factory(int x) 
     { 
      inst = x.ToString(); 
      return inst; 
     } 

     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); 
       }   
      } 
     } 

public void uu(string newvalue) 
{ 
    this.textBox1.Name = (newvalue); 
} 

static int k=0; 
private void button1_Click(object sender, EventArgs e) 
{ 
    k = 1; 
    intostring(k); 
} 

private void Form1_Load(object sender, EventArgs e) 
{ 
    EventExample myevt = new EventExample(); 
    myevt.Valuechanged += new myeventhandler(uu); 
    myevt.val = inst;       
    } 
} 

}

+0

它一个int转换为字符串 – user1853846 2013-03-17 23:00:54

回答

0

只要里面的button1_Click

private void button1_Click(object sender, EventArgs e) 
{ 
    k = 1; 
    intostring(k); 
    this.textBox1.Text = thevalue; 
} 
+0

你是对的设置。但这不是整个代码。我想因为当变量“inst”改变时我不使用ref关键字,它的改变不适用于“val”变量,所以它不能引发事件。我对吗? – user1853846 2013-03-17 23:23:50

+0

@ user1853846你不清楚你想达到什么目的。你可以解释吗? – VladL 2013-03-18 06:47:52