简体   繁体   中英

Partial Class Winform Form

It was taught to me that any alterations to an object on a form (change the text, make visible/invisible or change the color and so on) should be done in the corresponding form class.

But due to the large amount of such alterations done inside the project, the file has became large and hard to search through. I've read online that a Partial Class could help, but there was no explanation on how to implement this. As an easy example, I have the following 2 files: Form_Main.cs

namespace Test
{
    partial class Form_Main : Form
    {
        public Form_Main()
        {
             InitializeComponent();    
        }
    }
}

AND Form_Main.Dataloader.cs

 namespace Test
    {
        partial class Form_Main : DataLoader
        {
            public void SetText()
            {
                TextBox_StudentSurname.Text = "1";        
            }
        }
    }

How can I make this work? Because if I do this I get several errors in the designer. 在此处输入图像描述

Your main problem is the first error printed: You cannot declare different base classes in different partial implementations. I don't know which of the two base classes is the right one (the one you previously used), but as always, a class cannot have two base classes. It is legal to specify the base class only in one of the parts, but if it is specified multiple times, it must be the same.

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