c# 窗体之间传递值 --转载

 

 

转载自: http://www.wangchao.net.cn/it/detail_52411.html

代码
父窗口:
  
using System;
  
using System.Collections.Generic;
  
using System.ComponentModel;
  
using System.Data;
  
using System.Drawing;
  
using System.Text;
  
using System.Windows.Forms;
  
namespace mail
  ...{
  
public partial class Form1: Form
   ...{
  
  
  
private string searchUrl = null;
  
public Form1()
   ...{
   InitializeComponent();
   }
  
public string SearchUrl
   ...{
  
get
   ...{
  
return searchUrl;
   }
  
set
   ...{
   searchUrl
= value;
   }
   }
  
private void Form1_Load(object sender, EventArgs e)
   ...{
   Form2 form2
= new Form2();
   form2.Owner
= this;
   form2.ShowDialog();
   }
   }
  }
  子窗口:
  
using System;
  
using System.Collections.Generic;
  
using System.ComponentModel;
  
using System.Data;
  
using System.Drawing;
  
using System.Text;
  
using System.Windows.Forms;
  
namespace mail
  ...{
  
public partial class Form2: Form
   ...{
  
public Form2()
   ...{
   InitializeComponent();
   }
  
private void setParent()
   ...{
   Form1 f
= (Form1)this.Owner;
   f.SearchUrl
= "www.baidu.com";
   }
   }
  }(王朝网络 wangchao.net.cn)

 

posted on 2010-11-03 15:01  蓝蓝的天2016  阅读(151)  评论(0编辑  收藏  举报