最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
asp.net 窗口之间值、控件的传递值
时间:2011-02-18 编辑:简简单单 来源:一聚教程网
asp教程.net 窗口之间值、控件的传递值
一、值的传递,很简单,因为在同一名称空间下,所以只需在要提供值的窗口里将值声明为public后,就可以在要引用值的窗口里通过“类名.变量名”使用了。如:
mainwindow.cs里:
public string test;
private void button2_click(object sender, routedeventargs e)
{
mytest test = new mytest();
test.showdialog();
}
在mytest.cs里:
public mytest()
{
initializecomponent();
mainwindow mw= new mainwindow();
this.content = mw.test;
}
二、控件的传递,和值传递类似,但需要更改子窗口的构造函数,在主窗口初始化时传递控件,如,我们现在传一个datagrid控件,并攻取它选中的值。
在mytest.cs里:
public mytest(datagrid mydg)
{
dg = mydg;
initializecomponent();
albums alb=new albums();
alb=dg.items[dg.selectedindex] as albums;
this.content = alb.title;
}
mainwindow.cs里:
private void button2_click(object sender, routedeventargs e)
{
mytest test = new mytest(datagrid1);
test.showdialog();
}
-
下一个: asp.net C#中抽象类和接口
相关文章
- C#复制数组的两种方式及效率比较解读 10-24
- ASP.NET Identity用法解析 10-24
- ASP.NET MVC使用Identity增删改查用户介绍 10-24
- C语言中atoi函数模拟实现介绍 10-18
- .Net反向代理组件Yarp用法介绍 10-10
- .NET使用YARP通过编码方式配置域名转发实现反向代理教程 10-10