2013-03-17 37 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