المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Passing and displaying variables in forms



C# Programming
01-25-2010, 01:10 PM
Hi All, just a note before you start reading, I wanted to apologize in advance for going into so much detail but I wanted to be thorough... if perhaps confusing in places





OK, so whats happening is that I'm having trouble getting data to display when they are passed to a form.

What's meant to happen is that the form NotesWindow (form2) (which is initialized by the main form) is meant to initialize a third form NewNoteWindow (form3) which takes text input from the user and then passes it back to NotesWindow (form2) which is meant to display it in a listbox.

I have managed to, using a constructor pass the data from NewNoteWindow (form3) to NotesWindow (form2) but it will only display if I hide NotesWindow (form2) after getting it to open NewNoteWindow (form3) and then using Notes********Show() from NewNoteWindow (form3) to bring up the form again.

My theory as to why this is happening is that I initialize NewNoteWindow (form3) from NotesWindow (form2) using NewNoteWindow newNoteWindow = new NewNoteWindow and then to pass the data back I need to initialize NotesWindow (form2) in NewNoteWindow (form3) using NotesWindow notesWindow = new NotesWindow I suspect that this is creating a new instance of NoteWindow (form2) and sending the data to that as opposed to the already open NotesWindow (form2).

If I'm right about that, anyone know how to send the data back to NotesWindow (form2) properly, if I'm wrong then anyone know what I'm doing wrong?

I'll include what I believe to be the relevant pieces of code at the bottom, if u want any more of the code or if you need me to clarify anything just ask.

Another problem I have had is that when I go to input a second piece of data the listbox is cleared of its data, I don't know if this is because of the this.hide() and Notes********Show methods or because I'm initializing another instance of NotesWindow (form2) (I believe it's this reason) or something completely different.


Thanks in advance for any insight you can offer about my problem.



Relevant Code In NotesWindow (Form2)


NewNoteWindow newNoteWindow = new NewNoteWindow();



public string NewNote1
{
set
{
notesDisplayBox.Items.Add(value);
label1.Text = value;
}
}



private void addNewButton_Click(object sender, EventArgs e)
{
newNote********ShowDialog();
//<span class="code-comment">this.Hide();