简体   繁体   English

在Winform应用程序中操作UserControl事件/属性/方法/枚举等

[英]Manipulation of UserControl event / properties / method / enum etc. in Winform application

I have 200+ UserControls on form1.cs (Winforms application) and confuse between event / method / properties and enum of each UserControls which are not in proper order in form1.cs coding page. 我在form1.cs (Winforms应用程序)上有200多个UserControl,并且混淆了每个form1.cs事件/方法/属性和枚举,这些在form1.cs编码页面中顺序不正确。

I can order them by manually like set comment like // and by provide identity manually. 我可以通过像//这样的注释设置手动排序,也可以手动提供身份。

I want to know is there a different way to handle them by a specific method or any other way? 我想知道是否有其他方法可以通过特定方法或其他任何方式来处理它们?

For Example: 例如:

namespace FinApps
{
public partial class Form1 : Form
{
    private FinAppsUserControl.ExportReports er;
    private FinAppsUserControl.BankMaster bankmaster;
    private FinAppsUserControl.CompanyMaster companymaster;

    public Form1()
    {
        er = new FinAppsUserControl.ExportReports();
        bankmaster = new FinAppsUserControl.BankMaster();
        companymaster = new FinAppsUserControl.CompanyMaster();

        InitializeComponent();

        this.panel2.Controls.Add(er);
        this.panel2.Controls.Add(bankmaster);
        this.panel2.Controls.Add(companymaster);

      bankmaster.BankMasterExitEvent += new FinAppsUserControl.BankMaster.bankmasterexitevent(bankmaster_BankMasterExitEvent);
        er.ExportReportsKeyDownEvent += new FinAppsUserControl.ExportReports.exportreportskeydownevent(er_ExportReportsKeyDownEvent);
        companymaster.CloseEvent += new FinAppsUserControl.CompanyMaster.closeevent(companymaster_CloseEvent);
     }


//below is mix event/properties/method not sorted by specific UserControl Order..

    private void er_ExportReportsKeyDownEvent(ref Message msg, Keys keydata)
    {
        if (keydata == Keys.Escape) 
        {
        // specific tasks          
        }
    }
 private void bankmaster_BankMasterExitEvent()
 {
      //specific tasks
 }

 private void companymaster_CloseEvent()
 {
        //specific tasks
 }

but I want to sort event/method/properties of Specific UserControl vide specific Usercontrol vise like below which I manually adjusted. 但是我想对“特定用户控件”的事件/方法/属性进行排序,例如“我手动调整的特定用户控件”。

    //ExportReportUserControl
    private void er_ExportReportsKeyDownEvent(ref Message msg, Keys keydata)
    {
        if (keydata == Keys.Escape) 
        {
        // specific tasks          
        }
    }

   //BankMasterUserControl
 private void bankmaster_BankMasterExitEvent()
 {
      //specific tasks
 }

  //CompanyMasterUserControl

 private void companymaster_CloseEvent()
 {
        //specific tasks
 }

The above example are related to only three UserControl and there may about 200+ UserControls and each UserControls may be contain more Event/Method/Properties and Enum on Form1.cs coding page. 上面的示例仅与三个UserControl有关,并且大约有200多个UserControl,并且每个Form1.cs编码页面上的每个UserControl可能包含更多的事件/方法/属性和枚举。 I just want to sort them by specific UserControl Idenetity which I have manually declared above by comment // . 我只想按上面通过注释//手动声明的特定UserControl意识对它们进行排序。

So my idea about to declare a specific method in form1.cs which is related to specific UserControls which contain individually their event/method/properties/enum and thus we can easily solve the above confusion. 因此,我想在form1.cs中声明一个特定方法,该方法与特定的UserControls有关,后者分别包含其event / method / properties / enum,因此我们可以轻松解决上述混淆。

Is it possible?. 可能吗?。 Or any other better way?. 还是其他更好的方法?

You can use #region - #endregion tags, for example: 您可以使用#region-#endregion标签,例如:

#region MyUserControl1 things

//Put your MyUserControl1 methods, event handlers etc. here

#endregion

#region MyUserContro2 things

//Put your MyUserContro2 methods, event handlers etc. here

#endregion

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM