Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

How can I click a Button in one form and update text in a TextBox in another form?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
316 views
Welcome To Ask or Share your Answers For Others

1 Answer

If you're attempting to use WinForms, you can implement a custom event in your "child" form. You could have that event fire when the button in your "child" form was clicked.

Your "parent" form would then listen for the event and handle it's own TextBox update.

public class ChildForm : Form
{
    public delegate SomeEventHandler(object sender, EventArgs e);
    public event SomeEventHandler SomeEvent;

    // Your code here
}

public class ParentForm : Form
{
    ChildForm child = new ChildForm();
    child.SomeEvent += new EventHandler(this.HandleSomeEvent);

    public void HandleSomeEvent(object sender, EventArgs e)
    {
        this.someTextBox.Text = "Whatever Text You Want...";
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...