Click here to Skip to main content
15,913,773 members
Home / Discussions / C#
   

C#

 
GeneralRe: Speechlib Pin
wernlin25-Nov-13 5:03
wernlin25-Nov-13 5:03 
GeneralRe: Speechlib Pin
Dave Kreskowiak25-Nov-13 9:27
mveDave Kreskowiak25-Nov-13 9:27 
GeneralRe: Speechlib Pin
wernlin25-Nov-13 20:57
wernlin25-Nov-13 20:57 
GeneralRe: Speechlib Pin
Dave Kreskowiak26-Nov-13 1:21
mveDave Kreskowiak26-Nov-13 1:21 
GeneralRe: Speechlib Pin
wernlin26-Nov-13 1:39
wernlin26-Nov-13 1:39 
GeneralRe: Speechlib Pin
Dave Kreskowiak26-Nov-13 4:13
mveDave Kreskowiak26-Nov-13 4:13 
GeneralRe: Speechlib Pin
wernlin27-Nov-13 5:30
wernlin27-Nov-13 5:30 
Questionchange text from form Pin
messages25-Nov-13 3:33
messages25-Nov-13 3:33 
AnswerRe: change text from form Pin
Richard MacCutchan25-Nov-13 4:54
mveRichard MacCutchan25-Nov-13 4:54 
GeneralRe: change text from form Pin
messages25-Nov-13 5:20
messages25-Nov-13 5:20 
GeneralRe: change text from form Pin
Richard MacCutchan25-Nov-13 5:39
mveRichard MacCutchan25-Nov-13 5:39 
GeneralRe: change text from form Pin
messages25-Nov-13 5:50
messages25-Nov-13 5:50 
GeneralRe: change text from form Pin
Richard MacCutchan25-Nov-13 6:23
mveRichard MacCutchan25-Nov-13 6:23 
AnswerRe: change text from form Pin
OriginalGriff25-Nov-13 5:04
mveOriginalGriff25-Nov-13 5:04 
GeneralRe: change text from form Pin
messages25-Nov-13 5:19
messages25-Nov-13 5:19 
GeneralRe: change text from form Pin
OriginalGriff25-Nov-13 5:23
mveOriginalGriff25-Nov-13 5:23 
GeneralRe: change text from form Pin
messages25-Nov-13 5:48
messages25-Nov-13 5:48 
GeneralRe: change text from form Pin
OriginalGriff25-Nov-13 6:00
mveOriginalGriff25-Nov-13 6:00 
GeneralRe: change text from form Pin
messages25-Nov-13 6:32
messages25-Nov-13 6:32 
GeneralRe: change text from form Pin
OriginalGriff25-Nov-13 7:59
mveOriginalGriff25-Nov-13 7:59 
GeneralRe: change text from form Pin
messages26-Nov-13 3:59
messages26-Nov-13 3:59 
GeneralRe: change text from form Pin
OriginalGriff26-Nov-13 5:01
mveOriginalGriff26-Nov-13 5:01 
GeneralRe: change text from form Pin
messages26-Nov-13 5:22
messages26-Nov-13 5:22 
GeneralRe: change text from form Pin
OriginalGriff26-Nov-13 5:56
mveOriginalGriff26-Nov-13 5:56 
AnswerRe: change text from form Pin
BillWoodruff25-Nov-13 5:08
professionalBillWoodruff25-Nov-13 5:08 
Unless there is a compelling reason to create new instances of the Forms with every click of the Button(s), then you want to create the two Forms once.

There are many ways you could have the two Forms interact; the method shown here works by giving each Form a valid reference to the other Form.

In the case of Form1, the "Main Form," which creates Form2: by definition, it "knows about" ... has a valid reference to ... Form2.

Look at the Load EventHandler in Form1: notice that it sets the Public Property of Type Form1 in Form2 with a valid reference to Form1.

Form1:
C#
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    Form2 form2 = new Form2();

    private void Form1_Load(object sender, EventArgs e)
    {
        // form2 gets a reference to this instance of Form1
        form2.referenceToForm1 = this;
    }

    private void button1_Click(object sender, EventArgs e)
    {
        form2.Text = textBox1.Text;
        form2.Show();
        Hide();
    }
}
Form 2:
C#
public partial class Form2 : Form
{
    public Form2()
    {
        InitializeComponent();
    }

    // holds the reference to Form1
    public Form1 referenceToForm1 { get; set; }

    private void button1_Click(object sender, EventArgs e)
    {
        referenceToForm1.Text = textBox1.Text;
        referenceToForm1.Show();
        Hide();
    }
}
Note that you could get into an "undefined" state if you did this:

1. clicked the Button on form1 which would show form2, and hide form1

2. then, closed form2: at that point your Application is still running, and form1 is hidden ... so it won't show in the TaskBar, so: you are now running in "outer space," and HAL will not open the pod-bay doors.

Finally, I am not sure why you are implementing this kind of functionality which I find rather strange: perhaps as a learning experiment ?
"What Turing gave us for the first time (and without Turing you just couldn't do any of this) is he gave us a way of thinking about and taking seriously and thinking in a disciplined way about phenomena that have, as I like to say, trillions of moving parts.

Until the late 20th century, nobody knew how to take seriously a machine with a trillion moving parts. It's just mind-boggling." Daniel C. Dennett

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.