I have a form, now if I were to make a new class and make the form inherit that class. That class changes to a form? Can anyone explain why.

This is probably a really silly question but I cannot find an explanation for it!

Thanks
James

Recommended Answers

All 2 Replies

Here is some simple example how to use form and class:

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            string value = "ABC";
            NewClass nc = new NewClass(value);
            nc.MyMethod();
        }
    }

    public class NewClass
    {
        string classVariable;
        public NewClass(string parameter)
        {
            //constructor!
            string methodVariable = parameter;
            classVariable = methodVariable;
            //you can assign parameter directly to the classVariable!
        }

        public void MyMethod()
        {
            System.Windows.Forms.MessageBox.Show("This is a method in a new class, with the value: " + classVariable);
        }
    }

yes if you inherit a class from your form then the class will change to a form. As we all know when ever we inherit a class from any other class it contains all the functions of the parent class.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.