2013-07-19 18 views
0
public partial class Form3 : Form 
{ 
     public Form3() 
     { 
      InitializeComponent(); 
     } 

     int port;  // I declared a variable and I wanna use this in another form like 
} 

// ------------------------------------------------------- // 

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

     void menu1_Click(object sender, EventArgs e) 
     { 
      Form2 frq = new Form2(); 
      frq.Show(); 

      MessageBox.Show("{0} server is online ",port); //How to I declare ???? 
     } 

} 

回答

0

最好的辦法是爲它創建一個屬性。

試試這個

public partial class Form3 : Form 
{ 
    int _port; 
    public int Port 
    { 
     get { return _port; } 
     set { _port = value; } 
    } 
} 

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

    void menu1_Click(object sender, EventArgs e) 
    { 
     Form2 frq = new Form2(); 
     frq.Show(); 
     Form3 frm3 = new Form3(); 
     frm3.Port = 8080; 

     MessageBox.Show("{0} server is online ", frm3.Port); 
    } 

} 
+0

是frm3.Port = 8080;你的聲明權利只是表明這一點? –

+0

什麼?對不起,我沒有得到你。你在這條線上發生了什麼錯誤? – yogi

0

你必須改變端口公衆。

公共部分類Form3:表 { 公共Form3() {

 InitializeComponent(); 

    } 

    public int port; <<== Change to public 

或公衆詮釋端口{獲取;集;}

相關問題