Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It's not allowed to inherit from two base classes. You can only inherit from one class but implement in addition as many interfaces as you want. Try like this:</p> <pre><code>public ref class Form2 : public Form1 { </code></pre> <p>In your case you do not need to inherit from two classes because Form1 already inherits System.Windows.Forms.Form and if Form2 inherits Form1 it's also automatically of the type System.Windows.Forms.Form.</p> <p>If it's just one variable that both forms should have in common and nothing else, why do you want to use inheritance? Because inheritance means in general to extend the base class so that ALL members/properties/methods of Form1 are also available in Form2. Because the forms must inherit from System.Windows.Forms.Form you cannot use any other base class. Perhaps you should think about using a common Interface that defines the common variable as a property and then, both forms have to implement that interface.</p> <pre><code>public interface IMyForm { int MyValue { get; set; } } public class Form1 : System.Windows.Forms.Form, IMyForm { public int MyValue { get; set; } ... } public class Form2 : System.Windows.Forms.Form, IMyForm { public int MyValue { get; set; } ... } </code></pre> <p>Sorry for the C# syntax, hope it becomes clear what I mean. If you have now a method that expects a form with that common property as a parameter for example you can simple do that:</p> <pre><code>public void DoSomething(IMyForm form) { form.MyValue = 5; } </code></pre> <p>And you can pass an instance of Form1 or Form2 as the parameter.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload