C#窗口間傳值一例(子窗口向父窗口傳值

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,EventArgse)
{
Form2form2
= 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()
{
Form1f
= (Form1) this .Owner;
f.SearchUrl
= " www.baidu.com " ;
}

}

}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章