我希望這是你要搜索的內容...
代碼爲Form1:對窗體2
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Form2 frm = new Form2();
DialogResult res = frm.ShowDialog();
if (res != System.Windows.Forms.DialogResult.OK)
{
frm.Dispose();
return;
}
this.txtMaKeHoach.Text = frm.ChosenEntry;
frm.Dispose();
}
}
代碼:
public partial class Form2 : Form
{
private string _ChosenEntry = "";
public Form2()
{
InitializeComponent();
}
private void btnChoose_Click(object sender, EventArgs e)
{
//...
_ChosenEntry = this.dataGridView1.SelectedCells[0].Value.ToString();
this.DialogResult = System.Windows.Forms.DialogResult.OK;
this.Close();
}
public string ChosenEntry
{
get { return _ChosenEntry; }
}
}