Form1调用一个新窗体frm,谢谢大家给予方法! 本帖最后由 yjrdf 于 2009-11-13 11:21:14 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 没看懂你说的啥意思,如要你是想要新new一个form且加控件的话,可以如下: private void button1_Click(object sender, EventArgs e) { //定义一个Form Form fm = new Form(); //定义一个控件 Button btn = new Button(); btn.Text = "New Button"; //把控件加到Form里 fm.Controls.Add(btn); fm.Show(); } 我想在新调用的frm中进行操作,添加的控件具有执行能力,就是说我怎么在新的form中添加的button中写代码执行操作呢呢?还有我们这样添加的button的位置怎么进行设置呀? 十分感谢! 添加完button以后给加个click事就有执行能力了button的位置可以用location来设置的 private void button1_Click(object sender, EventArgs e) { //定义一个Form Form fm = new Form(); //定义一个控件 Button btn = new Button(); //回答:还有我们这样添加的button的位置怎么进行设置呀?---给Location赋值就行 btn.Location = new Point(10, 10); //回答:就是说我怎么在新的form中添加的button中写代码执行操作呢呢?---给其加事件就行 btn.Click += new EventHandler(btn_Click); btn.Text = "New Button"; //把控件加到Form里 fm.Controls.Add(btn); fm.Show(); } //新加button的click 事件 private void btn_Click(object sender, EventArgs e) { MessageBox.Show(((Button)sender).Text); } 已经回复你留言了,怕你收不到,再在这里说一下,你把textBox定义在方法外面就行 为什么不在设计的时候就把frm设置好...只是在程序主入口点调用的是Form1Application.Run(new Form1());这样不好...然后Button单击调用frm?不懂... 呵呵 因为我的两个界面都是要有人机交互式的,就是说在Form1,和新调用窗体fm中都有我要输入的东西进行选择,在选择完Form1后接着才进行fm中的操作。呵呵,谢谢指点! c#实现用一个winform程序监控操纵一个windows服务 C#位图空白处的填充 一个小问题,请教 C#如何判断一台机器的网络状态即是否连上互联网? C#的Array类如何使用?如Array c;那么c能当作数组使用吗?如c[8]=5;这样用对吗? 仪器仪表管理 用C 来做 C#脱离vs还会存在吗? 刚签了约,散分庆祝一下 C#写excel,为什么我这回弹出两次保存,第2次保存的一个空excel 在页面刷新时如何保持变量的值 高手,大哥请帮忙:c#中想利用Form1调用一个新窗体frm,但想在frm中写代码,怎么实现呀,谢谢! 谁做过C#序列号?急。。
{
//定义一个Form
Form fm = new Form();
//定义一个控件
Button btn = new Button();
btn.Text = "New Button";
//把控件加到Form里
fm.Controls.Add(btn);
fm.Show();
}
button的位置可以用location来设置的
private void button1_Click(object sender, EventArgs e)
{
//定义一个Form
Form fm = new Form();
//定义一个控件
Button btn = new Button();
//回答:还有我们这样添加的button的位置怎么进行设置呀?---给Location赋值就行
btn.Location = new Point(10, 10);
//回答:就是说我怎么在新的form中添加的button中写代码执行操作呢呢?---给其加事件就行
btn.Click += new EventHandler(btn_Click);
btn.Text = "New Button";
//把控件加到Form里
fm.Controls.Add(btn);
fm.Show();
}
//新加button的click 事件
private void btn_Click(object sender, EventArgs e)
{
MessageBox.Show(((Button)sender).Text);
}
只是在程序主入口点调用的是Form1
Application.Run(new Form1());
这样不好...
然后Button单击调用frm?
不懂...