0

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

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by abelLazm
0

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);
        }
    }
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.