110,539
社区成员
发帖
与我相关
我的任务
分享
public partial class Form1 : Form
{
public static Form1 fm1; //定义
public Form1()
{
InitializeComponent();
fm1 = this; //赋值
}
}
其他窗体/方法调用:
//Form1.fm1.xxx(控件/变量)
string text = Form.fm1.textBox1.Text
static class Program
{
//全局静态变量,放到Program类内
public static int MyProperty { get; set; }
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
public Form1()
{
InitializeComponent();
Program.MyProperty = 1;//调用全局变量
MessageBox.Show(Program.MyProperty.ToString());
}