110,539
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
UserControl1 uc = new UserControl1();
panel1.Controls.Add(uc);
}
private void button1_Click(object sender, EventArgs e)
{
string str = textBox1.Text;
Control[] c = panel1.Controls.Find("UserControl1", false);
foreach (Control control in c)
{
Control[] con=control.Controls.Find("TextBox1", false);
con[0].Text = str;
}
}
}
}
// UserControl1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication3
{
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
public void Init(string txt)
{
this.textBox1.Text = txt;
}
}
}
// Form1.cs
using System;
using System.Collections.Generic;
using System.Data;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
UserControl1 uc = new UserControl1();
uc.Init(this.textBox1.Text);
}
}
}