Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It's probably because you're trying to use functions that exist in your first window from the second one as if they were static, but they aren't.</p> <p>You can try to solve this problem this way:</p> <ul> <li><p>in the <strong>second</strong> form create a property with class of your first form, like:</p> <pre><code>class Form1 : Form { //this property will store reference to the first form public Form1 AssociatedFirstForm { get; set; } //... } </code></pre></li> <li><p>Then <strong>in the code where you create the second form</strong>, assign the first form to this property, which can look like this (if you create the second form from the first one):</p> <pre><code>... Form2 secondForm = new Form2(); secondForm.AssociatedFirstForm = this; ... </code></pre></li> </ul> <p>or like this (if you create both forms from another part of code):</p> <pre><code> ... Form1 firstForm = new Form1(); Form2 secondForm = new Form2(); secondForm.AssociatedFirstForm = firstForm; ... </code></pre> <ul> <li><p>then, in your <strong>second</strong> form you should be able to call a method from the first form like this:</p> <pre><code>... var myResultFromAnotherWindow = this.AssociatedFirstForm.SampleMethodToCall(); ... </code></pre></li> </ul> <p>I suppose you should also read more about using <a href="http://msdn.microsoft.com/en-us/library/79b3xss3%28v=vs.80%29.aspx" rel="nofollow">static classes and class members</a> and <a href="http://msdn.microsoft.com/en-us/library/k6sa6h87%28v=vs.80%29.aspx" rel="nofollow">creating instances of objects</a>. It should make it clear to you how and when to use them.</p> <p><strong>Update</strong></p> <p>I haven't written it clear enough, but you should avoid to set expose methods or properties as public if it's not really needed. </p> <p>If you want to create good code structure in your application and learn how it should be done, look for some articles about object oriented programming.</p> <p>Some sample links:</p> <ul> <li><a href="http://www.c-sharpcorner.com/UploadFile/tusharkantagarwal/objectorientedcsharp11162005070743AM/objectorientedcsharp.aspx" rel="nofollow">http://www.c-sharpcorner.com/UploadFile/tusharkantagarwal/objectorientedcsharp11162005070743AM/objectorientedcsharp.aspx</a></li> <li><a href="http://msdn.microsoft.com/en-us/library/dd460654.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/dd460654.aspx</a></li> </ul> <p>Knowing <strong><em>eventing mechanism</em></strong> also can be useful: <a href="http://msdn.microsoft.com/en-us/library/awbftdfh.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/awbftdfh.aspx</a>.</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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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