在C#中控制来自另一个表单的表单组件

在C#中控制来自另一个表单的表单组件

本文介绍了在C#中控制来自另一个表单的表单组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有两种形式,第一种包含一些文本框,默认情况下Enabled Proprieties设置为false,我想在关闭第二种形式时将Enabled设置为true。



我尝试了什么:



我将修改设置为公共文本框



代码

have two forms , The first one contains some textboxes that the Enabled Proprieties is set to false by default , i want to set the Enabled to true when i'm closing the second form .

What I have tried:

I set the modifies to public for the textboxes

Code

private void Data_FormClosing(object sender, FormClosingEventArgs e)
    {
        Main frm = new Main();

        frm.bSave.Enabled = true;
        frm.bEdit.Enabled = true;
        frm.tClient.Enabled = true;
        frm.tType.Enabled = true;
        frm.tFirst.Enabled = true;
        frm.tSecond.Enabled = true;
        frm.tDriver.Enabled = true;
        frm.tCity.Enabled = true;
        frm.tDriver.Enabled = true;
        frm.tNumber.Enabled = true;
        frm.tPrice.Enabled = true;
    }

推荐答案



public partial class Main : Form
   {
       private static Main frm;
       static void frm_FormClosed(object sender,FormClosedEventArgs e)
       {
           frm = null;
       }
       public static Main getMainForm
       {
           get
           {
               if(frm==null)
               {
                   frm = new Main();
                   frm.FormClosed += new FormClosedEventHandler(frm_FormClosed);

               }
               return frm;
           }
       }





并双击第二种形式的datagridview





and by double clicking the datagridview in the the second form

private void dataGridView1_DoubleClick(object sender, EventArgs e)
       {

           Main.getMainForm.bSave.Enabled = true;
           Main.getMainForm.bSave.Enabled = true;
           Main.getMainForm.tClient.Enabled = true;
           Main.getMainForm.tType.Enabled = true;
           Main.getMainForm.tFirst.Enabled = true;
           Main.getMainForm.tSecond.Enabled = true;
           Main.getMainForm.tDriver.Enabled = true;
           Main.getMainForm.tCity.Enabled = true;
           Main.getMainForm.tNumber.Enabled = true;
           Main.getMainForm.tPrice.Enabled = true;

           this.Close();

       }


这篇关于在C#中控制来自另一个表单的表单组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 16:16