2

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");
        }
    }
}
4

2 回答 2

0

尝试手动修改Form.Designer.cs

在里面 :

  private void InitializeComponent()
  {

  }

只需将控制声明更改为:

private System.Windows.Forms.Textbox YourTextbox;

至:

public System.Windows.Forms.Textbox YourTextbox;
于 2013-05-27T08:00:47.603 回答
0

幸运的是,我有片刻跳出框框思考并尝试将每个对象传递给它的子对象,这与我最初将层次结构与子类的预期颠倒构建的做法相反。离墙或直觉,你是法官:

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();
    }
}
于 2013-05-27T23:11:46.773 回答