Form2 form = new Form2(this.label1); form.Show(); } form2中 public partial class Form2 : Form { public string a; public Form2() { InitializeComponent(); } public Form2(Label l1) { a = l1.Text.ToString(); InitializeComponent(); } private void Form2_Load(object sender, EventArgs e) { this.textBox1.Text = a; } }
方法一: public Class Session { public static string myString; public static int myInt; ...... } 通过Session.myString赋值,相当于全局变量。 方法二: 重载一个form b的构造函数,在构造函数里加入你想要传入的变量,建议传入一个类的实例,以后直接往里添加属性。
frm.XXX= textbox1.Text;
frm.Show();
2、winform b的构造函数带参,winform b里把参数保存起来
formB frm = new formB (textbox1.Text);
frm.Show();只说这两个实用的
控件到窗口的三种方式(双击、拖拽、拷贝)
控件调整及精确调整(ctrl、Shift结合使用)
对齐(直接拖动看设计时那个VS给的参照线)及格式菜单应用
锚定、停靠、Winform默认键及焦点、容器 命名规则(控件及类、方法、属性、事件等)
属性窗口、事件窗口、双击控件时默认事件
委托、事件、事件参数、事件引发
重构通用(把验证证重构、通过事件或观察者)2、FormCommunication
窗口调用及传值,由A-->B
a>调用窗口B(普通调用,不传值)
b>调用窗口B(通过构造函数传值)
c>调用窗口C(通过属性 传参数)
d>调用窗口D(通过适配控件属性)
e>调用窗口E(通过公开属性控件)
f>调用窗口F(通过三方变量传递)
3、FormCommunication2
窗口间传值,由B-->A
a>调用窗口B(直接取窗口属性值)
b>调用窗口B(观察者模式)
c>调用窗口C(委托和事件)
d>ListView控件应用
e>接口定义与使用
http://blog.csdn.net/flygoldfish
form1中
private void button1_Click(object sender, EventArgs e)
{
Form2 form = new Form2(this.label1);
form.Show();
}
form2中
public partial class Form2 : Form
{
public string a;
public Form2()
{
InitializeComponent();
}
public Form2(Label l1)
{
a = l1.Text.ToString();
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
this.textBox1.Text = a;
}
}
1、winform a中直接调用winform b,那么就比较简单了,因为winform b本身就是一个对象,可以通过在winform b中提供一个属性。调用的时候把值传递过去。2、如果winform a和winform b本身没有调用关系,比如在MDI中两子窗体,那么这种情况必须要取得winform b的引用,或者通过第三者来实现传递。感觉都比较简单的。不知道是否有用
在form a中有几个textbox,输入一些值,点一个按钮,调出另一form b,显示这form b上的reportviewer中的内容,这内容根据前一form中的textbox里的值改变。
报表是rdlc的,报表的数据来源是一个SQL Server存储过程。前面输入textbox中的值是传给存储过程的输入参数。
这种情况,更么处理更好?
在打印窗体中写一个方法。
public void SetDataSet(String sReportDataSourceName, DataTable dt, string sReportEmbededResource,string sReportTitle)
{dt.TableName = "table1";
Microsoft.Reporting.WinForms.ReportDataSource datasource = new Microsoft.Reporting.WinForms.ReportDataSource(sReportDataSourceName, dt); this.reportViewer1.LocalReport.DataSources.Clear();
this.reportViewer1.LocalReport.DataSources.Add(datasource); this.reportViewer1.LocalReport.ReportEmbeddedResource = sReportEmbededResource;
ReportParameter rptParaA = new ReportParameter("ReportTitle", sReportTitle);
this.reportViewer1.LocalReport.SetParameters(new ReportParameter[] { rptParaA }); }
里面需要的参数从查询窗体中传入行了!
public Class Session
{
public static string myString;
public static int myInt;
......
} 通过Session.myString赋值,相当于全局变量。
方法二:
重载一个form b的构造函数,在构造函数里加入你想要传入的变量,建议传入一个类的实例,以后直接往里添加属性。
http://blog.csdn.net/zhzuo/archive/2004/04/05/22027.aspx
窗体的参数传递
http://blog.csdn.net/zhzuo/archive/2006/05/05/708941.aspx#sec5