what wrong with my code [modified]
-
private void newToolStripMenuItem_Click(object sender, EventArgs e) { if (IsFormLoaded("form1")) return; else { Form1 frmshow = new Form1(); frmshow.MdiParent = this; frmshow.Show(); } } private bool IsFormLoaded(string formName) { bool FormLoaded = false; for (int i = 0; i < (this.OwnedForms.Length) - 1; i++) { if (this.OwnedForms[i].Name.ToString().TrimStart() == "formName") { this.OwnedForms[i].WindowState = FormWindowState.Normal; this.OwnedForms[i].Focus(); FormLoaded = true; } } return FormLoaded; } not functioning modified on Sunday, March 7, 2010 9:52 PM
-
private void newToolStripMenuItem_Click(object sender, EventArgs e) { if (IsFormLoaded("form1")) return; else { Form1 frmshow = new Form1(); frmshow.MdiParent = this; frmshow.Show(); } } private bool IsFormLoaded(string formName) { bool FormLoaded = false; for (int i = 0; i < (this.OwnedForms.Length) - 1; i++) { if (this.OwnedForms[i].Name.ToString().TrimStart() == "formName") { this.OwnedForms[i].WindowState = FormWindowState.Normal; this.OwnedForms[i].Focus(); FormLoaded = true; } } return FormLoaded; } not functioning modified on Sunday, March 7, 2010 9:52 PM
That would depend on what it's doing and what you expect it to do! Or were we just supposed to read your mind?
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009... -
private void newToolStripMenuItem_Click(object sender, EventArgs e) { if (IsFormLoaded("form1")) return; else { Form1 frmshow = new Form1(); frmshow.MdiParent = this; frmshow.Show(); } } private bool IsFormLoaded(string formName) { bool FormLoaded = false; for (int i = 0; i < (this.OwnedForms.Length) - 1; i++) { if (this.OwnedForms[i].Name.ToString().TrimStart() == "formName") { this.OwnedForms[i].WindowState = FormWindowState.Normal; this.OwnedForms[i].Focus(); FormLoaded = true; } } return FormLoaded; } not functioning modified on Sunday, March 7, 2010 9:52 PM
So you modified your post and we are still supposed to guess what is not working and what you expect it do?
Why is common sense not common? Never argue with an idiot. They will drag you down to their level where they are an expert. Sometimes it takes a lot of work to be lazy Individuality is fine, as long as we do it together - F. Burns Help humanity, join the CodeProject grid computing team here
-
private void newToolStripMenuItem_Click(object sender, EventArgs e) { if (IsFormLoaded("form1")) return; else { Form1 frmshow = new Form1(); frmshow.MdiParent = this; frmshow.Show(); } } private bool IsFormLoaded(string formName) { bool FormLoaded = false; for (int i = 0; i < (this.OwnedForms.Length) - 1; i++) { if (this.OwnedForms[i].Name.ToString().TrimStart() == "formName") { this.OwnedForms[i].WindowState = FormWindowState.Normal; this.OwnedForms[i].Focus(); FormLoaded = true; } } return FormLoaded; } not functioning modified on Sunday, March 7, 2010 9:52 PM
:wtf:
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.
-
private void newToolStripMenuItem_Click(object sender, EventArgs e) { if (IsFormLoaded("form1")) return; else { Form1 frmshow = new Form1(); frmshow.MdiParent = this; frmshow.Show(); } } private bool IsFormLoaded(string formName) { bool FormLoaded = false; for (int i = 0; i < (this.OwnedForms.Length) - 1; i++) { if (this.OwnedForms[i].Name.ToString().TrimStart() == "formName") { this.OwnedForms[i].WindowState = FormWindowState.Normal; this.OwnedForms[i].Focus(); FormLoaded = true; } } return FormLoaded; } not functioning modified on Sunday, March 7, 2010 9:52 PM
Off the top of my head, I'd guess you're missing a
break;
statement after settingFormLoaded
totrue
. /raviMy new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com
-
private void newToolStripMenuItem_Click(object sender, EventArgs e) { if (IsFormLoaded("form1")) return; else { Form1 frmshow = new Form1(); frmshow.MdiParent = this; frmshow.Show(); } } private bool IsFormLoaded(string formName) { bool FormLoaded = false; for (int i = 0; i < (this.OwnedForms.Length) - 1; i++) { if (this.OwnedForms[i].Name.ToString().TrimStart() == "formName") { this.OwnedForms[i].WindowState = FormWindowState.Normal; this.OwnedForms[i].Focus(); FormLoaded = true; } } return FormLoaded; } not functioning modified on Sunday, March 7, 2010 9:52 PM
-
private void newToolStripMenuItem_Click(object sender, EventArgs e) { if (IsFormLoaded("form1")) return; else { Form1 frmshow = new Form1(); frmshow.MdiParent = this; frmshow.Show(); } } private bool IsFormLoaded(string formName) { bool FormLoaded = false; for (int i = 0; i < (this.OwnedForms.Length) - 1; i++) { if (this.OwnedForms[i].Name.ToString().TrimStart() == "formName") { this.OwnedForms[i].WindowState = FormWindowState.Normal; this.OwnedForms[i].Focus(); FormLoaded = true; } } return FormLoaded; } not functioning modified on Sunday, March 7, 2010 9:52 PM
There are many ways to achieve a single instance form, and I suspect that the problem you are having is that the form name you are searching for doesn't exist in the OwnedForms collection.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
-
private void newToolStripMenuItem_Click(object sender, EventArgs e) { if (IsFormLoaded("form1")) return; else { Form1 frmshow = new Form1(); frmshow.MdiParent = this; frmshow.Show(); } } private bool IsFormLoaded(string formName) { bool FormLoaded = false; for (int i = 0; i < (this.OwnedForms.Length) - 1; i++) { if (this.OwnedForms[i].Name.ToString().TrimStart() == "formName") { this.OwnedForms[i].WindowState = FormWindowState.Normal; this.OwnedForms[i].Focus(); FormLoaded = true; } } return FormLoaded; } not functioning modified on Sunday, March 7, 2010 9:52 PM