| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 782 人关注过本帖
标题:子表单如果控制主表单的控件?
只看楼主 加入收藏
ld999
Rank: 1
等 级:新手上路
帖 子:147
专家分:0
注 册:2007-4-11
收藏
 问题点数:0 回复次数:2 
子表单如果控制主表单的控件?
初学,请大家指点,代码如下:

想实现在form2上用一个button修改form1上的一个textbox1的text值。谢谢
表单form1代码:

using System;
using System.Collections.Generic;
using
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
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 = "要修改这儿";

        }
    }
}
搜索更多相关主题的帖子: using 主表 表单 System 控件 
2008-06-11 17:23
fjfhnui
Rank: 1
等 级:新手上路
帖 子:57
专家分:0
注 册:2007-6-18
收藏
得分:0 
可以用构造函数传值过来
form1单机事件
private void button1_Click(object sender, EventArgs e)
        {
            Form2  form2 = new Form2 (textbox1);
            form2.Show();
        }
form2 要下面这样
textbox te;

public Form2(textbox t)
        {
            InitializeComponent();
          te=t;
        }






private void button1_Click(object sender, EventArgs e)
        {
           te=这里是你要赋的值 ;
this.close();
这样就可以传给form1的text1.text

        }
2008-06-11 19:34
ld999
Rank: 1
等 级:新手上路
帖 子:147
专家分:0
注 册:2007-4-11
收藏
得分:0 
再问一下,如果我的主表单form1是的控件是一个tabcontrol控件,我在form2中的一个按钮中希望关闭form1上的tabcontrol上的一个页或对tabcontrol进行其他操作,应该如何做,这里可不能传值了。
我现在是找不到这个控件。无法对它操作。
2008-06-11 21:52
快速回复:子表单如果控制主表单的控件?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011233 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved