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 ????
}
}
user2598412
问问题
457 次
3 回答
1
于 2013-07-19T07:26:32.343 回答
0
您必须将端口更改为公共端口。
公共部分类Form3:表格{公共Form3(){
InitializeComponent();
}
public int port; <<== Change to public
或公共 int 端口 {get;set;}
于 2013-07-19T07:27:51.047 回答
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);
}
}
于 2013-07-19T07:29:44.387 回答