子表单如果控制主表单的控件?
初学,请大家指点,代码如下:想实现在form2上用一个button修改form1上的一个textbox1的text值。谢谢
表单form1代码:using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace mycon
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{ } private void button1_Click(object sender, EventArgs e)
{
Form2 form2 = new Form2 (this);
form2.Show();
}
}
}表单form2代码:using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace mycon
{
public partial class Form2 : Form
{
public Form1 pParent = null;
public Form2(Form1 main)
{
InitializeComponent();
pParent = main;
} private void Form2_Load(object sender, EventArgs e)
{ } private void button1_Click(object sender, EventArgs e)
{
this.pParent.Text = "4344343";
//以下不能访问具体控件,不知道怎么弄了 // this.pParent.textbox1.text = "要修改这儿"; }
}
}
初学,请大家指点,代码如下:想实现在form2上用一个button修改form1上的一个textbox1的text值。谢谢
表单form1代码:using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace mycon
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{ } private void button1_Click(object sender, EventArgs e)
{
Form2 form2 = new Form2 (this);
form2.Show();
}
}
}表单form2代码:using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace mycon
{
public partial class Form2 : Form
{
public Form1 pParent = null;
public Form2(Form1 main)
{
InitializeComponent();
pParent = main;
} private void Form2_Load(object sender, EventArgs e)
{ } private void button1_Click(object sender, EventArgs e)
{
this.pParent.Text = "4344343";
//以下不能访问具体控件,不知道怎么弄了 // this.pParent.textbox1.text = "要修改这儿"; }
}
}
http://www.kingofcoders.com