添加2个WIN窗体,分别为 from1  form2 在form2中单击按钮来设置form1中按钮的标题
namespace WindowsFormsApplication9
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }        private void button1_Click(object sender, EventArgs e)
        {
            Form2 f2 = new Form2();
            f2.Show();
            
            
        }
        
    }
    
    
}namespace WindowsFormsApplication9
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }        private void button1_Click(object sender, EventArgs e)
        {
            Form1.button1.text = "Button1"; //窗体2中单击按钮1如何设置窗体1中按钮1的标题?
        }
    }
}
窗体传值

解决方案 »

  1.   

    你的代码错了吧Form1.button1.text = "Button1";
      

  2.   

    我不知道LZ这样的意义何在···你这样就把button1的text值用一个静态的类关联,这样你在form2中操作这个类就可以达到效果了
      

  3.   

    这一句错误代码只是想表达我想要实现类似这样的功能
    那我就写一个给你吧,采用委托方式,具体委托的用法你可以参考教科书、msdn什么的都可以找到它的知识Form1namespace WindowsFormsApplication2
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        private void button1_Click(object sender, EventArgs e)
            {
                Form2 f2 = new Form2();
                f2.SetTitle += SeTitleHandler;
                f2.Show();
            }        private void SeTitleHandler(object sender, CustomerArgs e)
            {
                button1.Text = e.Title;
            }
        }
    }
    Form2namespace WindowsFormsApplication2
    {
        public partial class Form2 : Form
        {
            public delegate void CustomerEventHandler(object sender,CustomerArgs e);
            public event CustomerEventHandler SetTitle;        public Form2()
            {
                InitializeComponent();
            }        private void button1_Click(object sender, EventArgs e)
            {
                if (SetTitle != null)
                {
                    SetTitle(this,new CustomerArgs("button1"));
                }
            }
        }    public class CustomerArgs : EventArgs
        {
            public string Title { get; private set; }        public CustomerArgs(string title)
            {
                Title = title;
            }
        }
    }
      

  4.   

    这一句错误代码只是想表达我想要实现类似这样的功能
    那我就写一个给你吧,采用委托方式,具体委托的用法你可以参考教科书、msdn什么的都可以找到它的知识Form1namespace WindowsFormsApplication2
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        private void button1_Click(object sender, EventArgs e)
            {
                Form2 f2 = new Form2();
                f2.SetTitle += SeTitleHandler;
                f2.Show();
            }        private void SeTitleHandler(object sender, CustomerArgs e)
            {
                button1.Text = e.Title;
            }
        }
    }
    Form2namespace WindowsFormsApplication2
    {
        public partial class Form2 : Form
        {
            public delegate void CustomerEventHandler(object sender,CustomerArgs e);
            public event CustomerEventHandler SetTitle;        public Form2()
            {
                InitializeComponent();
            }        private void button1_Click(object sender, EventArgs e)
            {
                if (SetTitle != null)
                {
                    SetTitle(this,new CustomerArgs("button1"));
                }
            }
        }    public class CustomerArgs : EventArgs
        {
            public string Title { get; private set; }        public CustomerArgs(string title)
            {
                Title = title;
            }
        }
    }
    虽然看不懂,但是好像很厉害的样子。