最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
asp.net 窗口之间值、控件的传递值
时间:2022-06-25 04:24:59 编辑:袖梨 来源:一聚教程网
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();
}
相关文章
- 第五人格佣兵护腕怎么用 第五人格佣兵护腕教学 04-28
- 崩铁星穹列车年度开拓报告活动怎么玩 星穹列车年度开拓报告网页活动介绍 04-28
- 逆水寒手游五子棋残局三十二怎么过 04-28
- 崩坏星穹铁道齐颂给谁用 04-28
- 火影忍者手游旋涡鸣人仙人模式怎么玩 04-28
- 原神怎么破坏磐键 原神破坏磐键的方法 04-28