Frage

I am trying to get information from an external class back to a textbox in the main form. However, monodevelop won't let me change the automatic form creation code so a textbox can be public and easily accessible. When I debug, any changes I make are overwritten.

So, I attempted to pass the text box by reference parameter to a subclass then change the value there. Didn't work.

Finally, I tried to use a listener to trigger a function in the form to change the value, still no luck. Reference: Stack Overflow Page

All routes lead to an infinite loop or failure because of the way I have this structured. Can someone please suggest a solution, and explain why the heck this keeps becoming an infinite loop? Thank you

public class MainClass
{
    //Get Information to here
    //textbox
    public static void Main()
    {
        ParentClass Parent = new ParentClass ();
    }
    public void print1 (string Test)
    {
        Console.WriteLine(Test);
    }
}
public class ParentClass : MainClass
{
    public ParentClass()
    {
        ChildClass child = new ChildClass ();
    }

    public void print2(string Test)
    {
        base.print1 (Test);
    }
}

public class ChildClass : ParentClass
{
    public ChildClass()
    {
        // Some code
    }

    public void print3(string Test)
    {
        base.print2(Test);
    }

    class Socket : ChildClass
    {
        //Asynchronous Socket
        public Socket()
        {
            //Start Listening
        }

        //Listener running, target function:
        void ListenerTargetFunction()
        {
            base.print3 ("Test");
        }
    }
}
War es hilfreich?

Lösung 2

Fortunately I had a moment of thinking outside the box and tried passing each object into its child object, conversely to my original screw up of building the hierarchy upside down from intended with subclasses. Off the wall or intuitive, you be the judge:

class Program
{
    public static void Main()
    {
        Console.WriteLine("Main");
        Console.ReadLine();
        Form oForm = new Form();
    }
}

public class Form
{
    public Parent oParent;
    public Form()
    {
        Console.WriteLine("Form");
        Console.ReadLine();
        Parent oParent = new Parent(this);
    }

    public void TargetFunction()
    {
        Console.WriteLine("Target Hit");
        Console.ReadLine();
    }
}

public class Parent
{
    Form oForm;
    Child oChild;
    public int hi = 1;
    public Parent(Form Form)
    {
        oForm = Form;
        Console.WriteLine("Parent");
        Console.ReadLine();
        oChild = new Child(oForm, this);
    }
}

public class Child
{
    Form oForm;
    Parent oParent;
    public Child(Form Form, Parent Parent)
    {
        Console.WriteLine("Child");
        Console.ReadLine();
        oForm = Form;
        oParent = Parent;

        oForm.TargetFunction();
    }
}

Andere Tipps

Try modifying manually the Form.Designer.cs

In the :

  private void InitializeComponent()
  {

  }

Just change the control declaration from:

private System.Windows.Forms.Textbox YourTextbox;

to:

public System.Windows.Forms.Textbox YourTextbox;
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top