C#-APP: Groupbox naming issue. Simple problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Gun Slinger
    New Member
    • Feb 2008
    • 27

    C#-APP: Groupbox naming issue. Simple problem

    Hi guys,

    I have a simple problem which i cant seem to figure out. Im not sure if its my fault, or just VS2008.. I have a group box, which i change its name to show a user that the contents of the group box have changed. It works fine the very first time i do this.

    But after i close the form, and then create a new instance of the form, the group box no longer allows me to change the name. Or it DOES change the name, however the drawing of the name does not occur. I have tried to invalidate it, but it didnt work.

    This is a totally new form, i dont know why this isnt a simple fix.. I also tried disposing it, but that makes it not able to be opened later for some reason.

    Cheers
    Gunsligner
  • PRR
    Recognized Expert Contributor
    • Dec 2007
    • 750

    #2
    could you post some code? you just wanna change the text right?

    Code:
    Button b = new Button();
                b.Location = new Point(50,300);
                groupBox1.Controls.Add(b);         
    
                groupBox1.Text = "PRR";

    Comment

    • Gun Slinger
      New Member
      • Feb 2008
      • 27

      #3
      hmm, there isnt really much code to post.

      As you said, its really just changing the .Text property. However, the odd thing is, i have two methods which do something else in the program, but at the end they both call a method which changes the groups name, but only one of these is actually successful. I cant see any errors in my code.

      The question i really want an answer to now, is how to make sure that when i do a form.close() and then open a form by doing something like

      form openForm = new (myFormType)
      openForm.Show()

      that it will actually be a totally new instance.

      Sometimes i leave text on the form i want to close, and when i open it again, the text is still there, so it REALLY isnt a new form!

      Comment

      • PRR
        Recognized Expert Contributor
        • Dec 2007
        • 750

        #4
        Originally posted by Gun Slinger
        hmm, there isnt really much code to post.

        As you said, its really just changing the .Text property. However, the odd thing is, i have two methods which do something else in the program, but at the end they both call a method which changes the groups name, but only one of these is actually successful. I cant see any errors in my code.

        The question i really want an answer to now, is how to make sure that when i do a form.close() and then open a form by doing something like

        form openForm = new (myFormType)
        openForm.Show()

        that it will actually be a totally new instance.

        Sometimes i leave text on the form i want to close, and when i open it again, the text is still there, so it REALLY isnt a new form!
        can you post some code?
        "call a method which changes the groups name"
        maybe you should call this first ...i mean the function that changes the name...
        Code:
        private void button1_Click(object sender, EventArgs e)
                {
                    //cal1();
        
                    //Read12();
                    Button myByte = new Button();
                    myByte.Location = new Point(50, 300);
        
                    groupBox1.Controls.Add(myByte);
                    groupBox1.Text = "PRR";
        
                    Form1 my = new Form1();
                    my.Show();
        
                }

        Comment

        • tlhintoq
          Recognized Expert Specialist
          • Mar 2008
          • 3532

          #5
          Originally posted by dirtbag
          can you post some code?
          "call a method which changes the groups name"
          maybe you should call this first ...i mean the function that changes the name...
          Code:
          private void button1_Click(object sender, EventArgs e)
                  {
                      //cal1();
          
                      //Read12();
                      Button myByte = new Button();
                      myByte.Location = new Point(50, 300);
          
                      groupBox1.Controls.Add(myByte);
                      groupBox1.Text = "PRR";
          
                      Form1 my = new Form1();
                      my.Show();
          
                  }
          Sometimes i leave text on the form i want to close, and when i open it again, the text is still there, so it REALLY isnt a new form!
          I so want to see that. But I'd be happy to see the code where you are closing the form. Are you sure you are using .Close() and not .Hide() ?

          Also.... In this code you create a button, then a GroupBox, add the button to the GroupBox, then make a new form.

          At what point do you add the groupbox to the new form? To me it looks like the button lives in the groupbox, but the groupbox is homeless. Of is groupBox1 a GroupBox on the parent form that is creating the new Form1 named 'my'?

          Without seeing the constructor code for your custom Form1 its hard to say why you continue to see the same text. Maybe the form reads data from the registry or an INI file you created, upon the creation of hte form? Is there a method that gets called that fills the form controls, possibly from global variables?

          Sometimes methods get called by events we don't even know are being fired during the creation of a form. SizeChange for example. I've been stung by that one during creation since the form does change size but I only saw it in my mind as a user changing it after creation. If you have formatting methods triggered by text changing, size changing, parent changed and so on its possible the data is being read back into the form before you ever see it on screen. Maybe an automatic Load/Save method triggered by text changes?

          Comment

          • PRR
            Recognized Expert Contributor
            • Dec 2007
            • 750

            #6
            Originally posted by tlhintoq
            I so want to see that. But I'd be happy to see the code where you are closing the form. Are you sure you are using .Close() and not .Hide() ?
            // Comments
            Actually i ditn close the form... just created new one .....abt the form hiding or closing.... i too had a lil prob in one of my project... if i remember correctly i had used static form objects and intialized them.. Closing the parent form is not the solution... You could create a few static objects of form and use them as needed...

            Also.... In this code you create a button, then a GroupBox, add the button to the GroupBox, then make a new form.

            At what point do you add the groupbox to the new form? To me it looks like the button lives in the groupbox, but the groupbox is homeless. Of is groupBox1 a GroupBox on the parent form that is creating the new Form1 named 'my'?

            // Comments
            gropubox is created right in the beginning....

            Without seeing the constructor code for your custom Form1 its hard to say why you continue to see the same text. Maybe the form reads data from the registry or an INI file you created, upon the creation of hte form? Is there a method that gets called that fills the form controls, possibly from global variables?

            // Comments
            // in case.. you want the same form created... you can create another object and change the text n other things.. n then call show...

            Sometimes methods get called by events we don't even know are being fired during the creation of a form. SizeChange for example. I've been stung by that one during creation since the form does change size but I only saw it in my mind as a user changing it after creation. If you have formatting methods triggered by text changing, size changing, parent changed and so on its possible the data is being read back into the form before you ever see it on screen. Maybe an automatic Load/Save method triggered by text changes?
            Code:
            public static Form1 parent;
            
            //in button click
            
            Button myByte = new Button();
                        myByte.Location = new Point(50, 300);
            
                        groupBox1.Controls.Add(myByte);
                        groupBox1.Text = "PRR";
            
                        
            
                        Form1 my = new Form1();
                        my.button1.Text = "Something Else";
                        my.groupBox1.Text = "NEW";
                        my.Show();
            
                        parent = this;
                        parent.Hide();
            i guess you may have to look into parent child forms... i dont think you can close the parent form.. or the first form object... you could hide it though ...

            Comment

            • PRR
              Recognized Expert Contributor
              • Dec 2007
              • 750

              #7
              let me see if i got you correctly:
              1. you create a form...
              2 .. on click of button or other events .. you want to create a new object of same form.. change the name of some buttons etc.. and show the changed stuff?
              well if thats the case then you could do one thing ....
              Code:
              Form1 my = new Form1();
                          my = this;
                         // you will get all the stuff of main form...
                          my.button1.Text = "Something Else";
                          my.groupBox1.Text = "NEW";
                          my.Show();
              3. you need not close or hide the parent form if you could do the above...
              4 . Incase you want to have separate forms... i suggest that you have some
              public static objects of main form....

              so did i understood wat u were tryin to say>? Do explain further... n post some code....

              Comment

              Working...