使用不同的形式 [英] working with different forms

查看:65
本文介绍了使用不同的形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用两个表单,每个表单上有两个按钮和一个文本框,另一个表单上有一个文本框。我希望单击表单1中的按钮1表单2应该出现并单击两个文本的按钮2颜色框应该更改

i am working with two forms with two buttons and one text box on each form1 and one text box on form2.i want on click of button 1 in form 1 form 2 should appear and on click of button 2 color of both text box should change

推荐答案

例如,请参阅此 Stack Overflow 问题:在C#中的两个窗体之间进行通信 [ ^ ]。
See, for instance, this Stack Overflow question: "Communicate between two windows forms in C#"[^].


希望它可以帮到你

在两者之间传递数据Windows窗体 [ ^ ]
Hope it might help you
Passing Data between Windows Forms[^]


我想你好我明白你的问题。因此,您不仅要打开一个新表单,还要更改第二个表单上文本框的背景颜色。所以这意味着你想在第一个表单中调用第二个表单事件。你可以这样做。



Hi there, I think I understood your problem. So you not only want to open a new form, but you want to change the backcolor of the textbox on the 2nd form. So it means you want to call the 2nd form event within the first form. You can do it as below.

//-----------------------------Form1----------------
 //Create form1 and add 1 textbox and 2 buttons on it
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        Form2 frm2 = new Form2();
        
        private void button1_Click(object sender, EventArgs e)
        {
           frm2.Show();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.BackColor = Color.Red;
            frm2.TextboxBackColor = Color.Red;
            frm2.button1_Click(sender, e);
        }
    }


//-----------------------------Form2----------------

//Create form2 and add one textbox and a button on it
    public partial class Form2 : Form
    {
        //Property to get the textbox back color from form1
        public Color TextboxBackColor { get; set; }
        public Form2()
        {
            InitializeComponent();
            //textBox1.BackColor = TextboxBackColor;
        }

        internal void button1_Click(object sender, EventArgs e)
        {
            textBox1.BackColor = TextboxBackColor;
        }
    }


这篇关于使用不同的形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆