一个窗体中的一个变量,我想在另一个窗体中应用该变量的值,请问该怎么处理? public static string aa;访问的时候窗体名.aa; 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public static string aa或者在有aa的窗体定义public String GetAA{ Get { return aa; }} 声明前一个form然后用f.aa 方法1:在项目中添加一个类Class1内容如下:using System;namespace WindowsApplication2{ /// <summary> /// Class1 的摘要说明。 /// </summary> public class Class1 { private static string str; public Class1() { // // TODO: 在此处添加构造函数逻辑 // } public string Str { get { return str; } set { str=value; } } }}在form1中button1中加入以下内容:private void button1_Click(object sender, System.EventArgs e){ string aa=textBox1.Text.Trim(); Class1 cls=new Class1(); cls.Str=aa; Form2 frm=new Form2(); frm.Show();}在form2中button1中加入以下内容:private void button1_Click(object sender, System.EventArgs e){ Class1 cls=new Class1(); textBox1.Text=cls.Str;}这样即可完成两个窗体间的变量传递(这是比较好的一种方法)方法2:在form窗口中加入声明:public static string str;在form2中button1中加入以下内容:private void button1_Click(object sender, System.EventArgs e){ str=textBox1.Text.Trim(); Form2 frm=new Form2(); frm.Show();}在form2中button1中加入以下内容:private void button1_Click(object sender, System.EventArgs e){textBox1.Text=Form1.str;} 请教C/S软件中常用的数据同步更新机制... 新手请教各位高手 开发语言执行效率之比?! 字符串怎么转换成日期? C#中怎么调用存储过程啊? WinForm 程序的部署安装包执行错误(MSI 文件)。请指点。 选择FileUpload1控件的图片直接显示在Image1控件 笨熊问题:webform的listBox问题!!!谢谢!!!! 在线等待:为什么表单中用:asp:textbox 递交文本时出错。 如何把控制台程序制作成后台执行程序????? 还是哪个问题,up有分, 已知姓名查找主键(id)用什么涵数
public String GetAA
{
Get
{
return aa;
}
}
然后用f.aa
在项目中添加一个类Class1
内容如下:
using System;namespace WindowsApplication2
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
public class Class1
{
private static string str;
public Class1()
{
//
// TODO: 在此处添加构造函数逻辑
//
} public string Str
{
get
{
return str;
}
set
{
str=value;
}
}
}
}在form1中button1中加入以下内容:
private void button1_Click(object sender, System.EventArgs e)
{
string aa=textBox1.Text.Trim();
Class1 cls=new Class1();
cls.Str=aa;
Form2 frm=new Form2();
frm.Show();
}在form2中button1中加入以下内容:
private void button1_Click(object sender, System.EventArgs e)
{
Class1 cls=new Class1();
textBox1.Text=cls.Str;
}
这样即可完成两个窗体间的变量传递(这是比较好的一种方法)方法2:
在form窗口中加入声明:
public static string str;在form2中button1中加入以下内容:
private void button1_Click(object sender, System.EventArgs e)
{
str=textBox1.Text.Trim();
Form2 frm=new Form2();
frm.Show();
}在form2中button1中加入以下内容:
private void button1_Click(object sender, System.EventArgs e)
{
textBox1.Text=Form1.str;
}