cant close a tabpage from another winform

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nikzworld
    New Member
    • Sep 2007
    • 6

    cant close a tabpage from another winform

    Hi guyz,


    need help....!!! i have tabcontrol1 in mainform1 which dynamically adds a new tabpage based on the no of times a button is clicked on the main menubar.

    eg:

    if tabpage1 is created dynamically, tabpage1 will be showing form2 inside it. Therz a button2 on form2 , on its clicking it should close tabpage1 along with form2 I tried this code on Form2,

    Form2
    ---------

    Button2_clickev ent
    {
    mainform1 obj = new mainform1();
    obj.tabcontrol1 .tabpages.remov e(tabpage1);
    }

    it doesnt show any response.....ca nt close.......

    plz help guyz........... ......urgent :(



    Thanks in advance
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    Welcome to TSDN. One problem you have appear to have is with referencing. Have a think about it not working and showing no errors. Is this the case?

    Comment

    • nikzworld
      New Member
      • Sep 2007
      • 6

      #3
      Originally posted by kenobewan
      Welcome to TSDN. One problem you have appear to have is with referencing. Have a think about it not working and showing no errors. Is this the case?


      thats right.....doesn t show any errors......... ..but on clickin.......n othin happens

      Comment

      • nikzworld
        New Member
        • Sep 2007
        • 6

        #4
        Originally posted by kenobewan
        Welcome to TSDN. One problem you have appear to have is with referencing. Have a think about it not working and showing no errors. Is this the case?

        tats right.......m in a fix........wat should i do?

        Comment

        • Plater
          Recognized Expert Expert
          • Apr 2007
          • 7872

          #5
          Well for starters:
          Code:
          Button2_clickevent
          { 
          mainform1 obj = new mainform1();
          obj.tabcontrol1.tabpages.remove(tabpage1);
          }
          You are creating a NEW instance of the mainform1 class, not editing an existing one. So you will not see anything happening and there will probably not be any errors. (Either that function does not error when that tab doesn't exist, or it already does)

          The original reply suggesting you think on why your references are wrong is correct.

          Comment

          • nikzworld
            New Member
            • Sep 2007
            • 6

            #6
            Originally posted by Plater
            Well for starters:
            Code:
            Button2_clickevent
            { 
            mainform1 obj = new mainform1();
            obj.tabcontrol1.tabpages.remove(tabpage1);
            }
            You are creating a NEW instance of the mainform1 class, not editing an existing one. So you will not see anything happening and there will probably not be any errors. (Either that function does not error when that tab doesn't exist, or it already does)

            The original reply suggesting you think on why your references are wrong is correct.

            HI Plater,

            I tried these codes u suggested but aint workin......... or any public function i defined inside mainform1 , i cant access it from button2 click event. wat is te reason???

            Comment

            • Shashi Sadasivan
              Recognized Expert Top Contributor
              • Aug 2007
              • 1435

              #7
              Originally posted by nikzworld
              HI Plater,

              I tried these codes u suggested but aint workin......... or any public function i defined inside mainform1 , i cant access it from button2 click event. wat is te reason???
              So...are you still using
              [CODE=cpp]mainform1 obj = new mainform1();[/CODE]

              cheers

              Comment

              • nikzworld
                New Member
                • Sep 2007
                • 6

                #8
                Originally posted by Shashi Sadasivan
                So...are you still using
                [CODE=cpp]mainform1 obj = new mainform1();[/CODE]

                cheers

                Thanks guyz for the support.got the answer. declared a custom event handler in my form1 and initiated it from mainform1. Bingo...there u have it..........Tha nkz guyz



                :)

                Comment

                Working...