简体   繁体   中英

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.

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. I just want to sort them by specific UserControl Idenetity which I have manually declared above by comment // .

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.

Is it possible?. Or any other better way?.

You can use #region - #endregion tags, for example:

#region MyUserControl1 things

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

#endregion

#region MyUserContro2 things

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

#endregion

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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