C# Multiple forms...
-
Hi, I had to create my own form to get files from my directory because i had to add allot of functionality not available on the system dialog boxes (done with that) now my problem is i need to pass on the selected files from my directory form to my main form...i can't get this to happen...can anyone help??...this is how i'm calling my second form: private void mnu_Open_Click(object sender, System.EventArgs e) { Form2 myMenu = new Form2(); Menu.Show(); }
-
Hi, I had to create my own form to get files from my directory because i had to add allot of functionality not available on the system dialog boxes (done with that) now my problem is i need to pass on the selected files from my directory form to my main form...i can't get this to happen...can anyone help??...this is how i'm calling my second form: private void mnu_Open_Click(object sender, System.EventArgs e) { Form2 myMenu = new Form2(); Menu.Show(); }
If I understand you correctly, you can have property ( or internal field) with data you want to pass... It can look like :
// your dialog class Form2:.... { ... public string[] Files { get { // m_files are return m_files; } } } // somewhere in main program private void mnu_Open_Click(object sender, System.EventArgs e) { Form2 myMenu = new Form2(); myMenu.Show(); DoSomethingWith(myMenu.Files); }
Does it help? bets regards, David 'DNH' Nohejl Never forget: "Stay kul and happy" (I.A.) -
If I understand you correctly, you can have property ( or internal field) with data you want to pass... It can look like :
// your dialog class Form2:.... { ... public string[] Files { get { // m_files are return m_files; } } } // somewhere in main program private void mnu_Open_Click(object sender, System.EventArgs e) { Form2 myMenu = new Form2(); myMenu.Show(); DoSomethingWith(myMenu.Files); }
Does it help? bets regards, David 'DNH' Nohejl Never forget: "Stay kul and happy" (I.A.)And out of mercy to those who might have to read your code, you might want to use a more meaningful name than "Form2" for the thing. As well,
myMenu = new Form();
is a bit confusing -- is it a form or a menu? Additionally, you might want to use ShowDialog() and also set the dialog result values appropriately, so you can use your dialog as you would an OpenFileDialog, for example:if( openFileDialog.ShowDialog(this) == DialogResult.OK )
{
//... use openFileDialog.FileName and whatnot ...
}Matt Gerrans
-
If I understand you correctly, you can have property ( or internal field) with data you want to pass... It can look like :
// your dialog class Form2:.... { ... public string[] Files { get { // m_files are return m_files; } } } // somewhere in main program private void mnu_Open_Click(object sender, System.EventArgs e) { Form2 myMenu = new Form2(); myMenu.Show(); DoSomethingWith(myMenu.Files); }
Does it help? bets regards, David 'DNH' Nohejl Never forget: "Stay kul and happy" (I.A.)Thanks that solved my problem.
-
And out of mercy to those who might have to read your code, you might want to use a more meaningful name than "Form2" for the thing. As well,
myMenu = new Form();
is a bit confusing -- is it a form or a menu? Additionally, you might want to use ShowDialog() and also set the dialog result values appropriately, so you can use your dialog as you would an OpenFileDialog, for example:if( openFileDialog.ShowDialog(this) == DialogResult.OK )
{
//... use openFileDialog.FileName and whatnot ...
}Matt Gerrans
Matt, I didn't ask you for your judgment i asked for some help. You unlike the other guy were of no assistance. Oh btw...I simplified the code down to a textbook manner so that i can get my point across without copying my entire file into the thread...next time give your opinion when asked for it.
-
Matt, I didn't ask you for your judgment i asked for some help. You unlike the other guy were of no assistance. Oh btw...I simplified the code down to a textbook manner so that i can get my point across without copying my entire file into the thread...next time give your opinion when asked for it.
Okay, sorry about adding the editorial. ;P I removed that part, but I hope at least the part about the ShowDialog() and the DialogResults was helpful. :) Matt Gerrans
-
Okay, sorry about adding the editorial. ;P I removed that part, but I hope at least the part about the ShowDialog() and the DialogResults was helpful. :) Matt Gerrans
You don't need to apoligize for correcting bad examples. Many times in this forum some people post bad examples that foster bad coding in other developers. Nothing leads to poor quality software than code written half-assed.