大家好!请教一个问题:(下面仅仅是一个示例问题,具体使用当中不是这么简单的)在VS2005中新建一个C#项目
1、新建主窗体 form1
2、在窗体中拖放一个文本框 textbox1 和按钮 Button13、然后创建一个自定义控件 usercontrol1
4、在用户自定义控件中托放入一个文本框 textbox15、输入“代码”编译执行
6、然后将自定义控件 usercontrol1 拖放入主窗体编译执行要实现的功能:在第 2 步的文本框 textbox1 中输入内容 123 ,点击提交按钮后,在主窗体自定义控件
文本框中也相应显示 123 !效果图:问题:请问第 5 步中的代码应该怎么写???请给出源代码!拜托大家了...
1、新建主窗体 form1
2、在窗体中拖放一个文本框 textbox1 和按钮 Button13、然后创建一个自定义控件 usercontrol1
4、在用户自定义控件中托放入一个文本框 textbox15、输入“代码”编译执行
6、然后将自定义控件 usercontrol1 拖放入主窗体编译执行要实现的功能:在第 2 步的文本框 textbox1 中输入内容 123 ,点击提交按钮后,在主窗体自定义控件
文本框中也相应显示 123 !效果图:问题:请问第 5 步中的代码应该怎么写???请给出源代码!拜托大家了...
解决方案 »
- 数据库文件访问权限问题
- 谁帮我解释一下C#中的CreateObject()方法。
- 多线程中高性能的界面更新的源代码
- 如何实现抽奖时身份证号码不断滚动呢?
- netscape 3.0中支持的html标志符
- 遍历一个表的所有字段,是否可以让输出时的字段不排序
- #################各位高手大哥看过来啊!#################
- 使用XmlDocument怎样注释掉一个节点
- 我用GDI画个图形,怎么我选不中它.我想画后选中?
- winform 中MDI父窗口传值给子窗口
- Request.QueryString更新问题。
- 子线程抛出引发类型为“System.OutOfMemoryException”的异常
在自定义控件里写个方法 public void Init(string txt)
{
this.txtUserControl.Text = txt;
}然后在你的Form里调这个方法把值传过来。
是下面的写法么??好像不能实现啊!// 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);
}
}
}
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 Form2 f2 = new Form2(); 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;
}
}
}
}
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;
}
}
}
}