Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. what wrong with my code [modified]

what wrong with my code [modified]

Scheduled Pinned Locked Moved C#
8 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    crisjala
    wrote on last edited by
    #1

    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

    D L L R P 7 Replies Last reply
    0
    • C crisjala

      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

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      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...

      1 Reply Last reply
      0
      • C crisjala

        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

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • C crisjala

          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

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          :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.


          1 Reply Last reply
          0
          • C crisjala

            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

            R Offline
            R Offline
            Ravi Bhavnani
            wrote on last edited by
            #5

            Off the top of my head, I'd guess you're missing a break; statement after setting FormLoaded to true. /ravi

            My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

            1 Reply Last reply
            0
            • C crisjala

              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

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              You Should First Compile it and Send the error message IF generate. Else Debug it Line By Line. Best Regard

              If you can think then I Can.

              1 Reply Last reply
              0
              • C crisjala

                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

                P Offline
                P Offline
                Pete OHanlon
                wrote on last edited by
                #7

                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.

                My blog | My articles | MoXAML PowerToys | Onyx

                1 Reply Last reply
                0
                • C crisjala

                  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

                  D Offline
                  D Offline
                  dybs
                  wrote on last edited by
                  #8

                  It looks like you might be missing a form in your loop. Dybs

                  The shout of progress is not "Eureka!" it's "Strange... that's not what i expected". - peterchen

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups