C#最简单的关闭子窗体更新父窗体的实现方法
程序员文章站
2023-11-21 11:02:46
主窗体form1关键代码: 将子窗体最为对话框模式弹出,当窗体关闭或取消时更新主窗体 复制代码 代码如下: private void simplebutton1_click...
主窗体form1关键代码:
将子窗体最为对话框模式弹出,当窗体关闭或取消时更新主窗体
private void simplebutton1_click(object sender, eventargs e)
{
form2 f2 = new form2();
f2.owner = this;
dialogresult result=f2.showdialog();
if (result == dialogresult.cancel)
{
this.gridcontrol1.datasource = f2.createtable();
}
}
子窗体
private void simplebutton1_click(object sender, eventargs e)
{
this.close();
}
public datatable createtable()
{
datatable tablea1 = new datatable();
tablea1.columns.addrange(new datacolumn[] { new datacolumn("名称"), new datacolumn("规格"), new datacolumn("单号"), new datacolumn("数量") });
tablea1.rows.add(new object[] { "螺旋", "ls-x", "111", "2" });
tablea1.rows.add(new object[] { "螺旋", "ls-x", "222", "1" });
tablea1.rows.add(new object[] { "指针", "lx-3", "523", "2" });
tablea1.rows.add(new object[] { "其他", "l-1", "666", "2" });
tablea1.rows.add(new object[] { "其他", "l-1", "456", "1" });
tablea1.rows.add(new object[] { "其他", "l-1", "990", "2" });
return tablea1;
}
将子窗体最为对话框模式弹出,当窗体关闭或取消时更新主窗体
复制代码 代码如下:
private void simplebutton1_click(object sender, eventargs e)
{
form2 f2 = new form2();
f2.owner = this;
dialogresult result=f2.showdialog();
if (result == dialogresult.cancel)
{
this.gridcontrol1.datasource = f2.createtable();
}
}
子窗体
复制代码 代码如下:
private void simplebutton1_click(object sender, eventargs e)
{
this.close();
}
public datatable createtable()
{
datatable tablea1 = new datatable();
tablea1.columns.addrange(new datacolumn[] { new datacolumn("名称"), new datacolumn("规格"), new datacolumn("单号"), new datacolumn("数量") });
tablea1.rows.add(new object[] { "螺旋", "ls-x", "111", "2" });
tablea1.rows.add(new object[] { "螺旋", "ls-x", "222", "1" });
tablea1.rows.add(new object[] { "指针", "lx-3", "523", "2" });
tablea1.rows.add(new object[] { "其他", "l-1", "666", "2" });
tablea1.rows.add(new object[] { "其他", "l-1", "456", "1" });
tablea1.rows.add(new object[] { "其他", "l-1", "990", "2" });
return tablea1;
}
上一篇: php中使用gd库实现下载网页中所有图片