Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

 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.
enter image description here

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading