Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Without knowing enough about your application I'll suggest that what you need is to invoke an event in the class that is handled by the form. What happens is like this:</p> <ol> <li>Class has an event.</li> <li>Form starts up and instantiates class.</li> <li>Form assigns a handler to the event in the class.</li> <li>Class does whatever it needs to do, until it reaches the point where it needs to communicate with the form.</li> <li>Class raises the event.</li> <li>The handler in the form gets executed and the textbox changes.</li> </ol> <p>So in the code of the class you'll need to add some definitions:</p> <pre><code>public delegate void FinishedEventHandler(object sender, string ValueToReturn); public event FinishedEventHandler Finished; </code></pre> <p>The first is a delegate with the <em>signature</em> of the event. By convention the first argument is always a reference to the instance of the class itself, and the rest are the values you want to return. The second is the actual event.</p> <p>Now, in the function that does whatever processing the class does we need to raise the event when appropriate:</p> <pre><code>void DoSomething() { . . . if(Finished!=null) Finished(this, "some value"); } </code></pre> <p>The if clause is used to make sure that someone is actually handling our event, otherwise we might get an exception.</p> <p>Now let's take a look at the form. We need to add a function that handles the event. It needs to have the same signature as the delegate we defined earlier. Within that function we do whatever changes we need to the form in light of the values we get back:</p> <pre><code>private void FinishedEventHandler(object sender, string ValueToReturn) { TextBox1.Text = ValueToReturn; } </code></pre> <p>Now we're ready to use all that plumbing we just created. First we add the handler to the event, then we can call the class's processing functions.</p> <pre><code>MyClass.Finished += FinishedEventHandler; MyClass.DoSomething(); </code></pre> <p>Here's a more detailed tutorial:</p> <p><a href="http://msdn.microsoft.com/en-us/library/aa645739(v=vs.71).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/aa645739(v=vs.71).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.
    3. 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