CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Threaded View

  1. #1
    Join Date
    Jun 2012
    Posts
    37

    Question Creating controls "on demand".

    Hi There, how are you? (Eri523, do you hear me? )

    I'm facing this problem, I'm not sure if there is a possible solution:

    I have 4 tabPages, each with 24 groupBoxes that are similar and contain textboxes, trackbars, etc. So that's a total of 96 groupBoxes, plus everything inside them!

    Each tabPage has a numeric up down that controls the visibility of these groupBoxes. So, for example, if only 5 is selected, only 5 groupBoxes will appear, although 24 do exist. I know, kinda amateur approach

    Problem is that I need a 5th tabPage, which will show the "visible" groupBoxes of all other tabPages together. So for example, if at tabPage1 user selected 2, tabPage2 user selected 5, tabPage3 user selected 1, tabPage4 user selected 3, tabPage 5 must show a CLONE of those groupBoxes, being a total of 11. (2 + 5 + 3 + 1 ).

    An obvious and reaaaally "newbie" solution for that would be having all 96 groupBoxes sitting there and invisible... As they must be shown, they're turned into Visible and the Drawing Point is recalculated so they won't overlap or have a gap in between. Of course I'm looking for something more neater and professional!

    I thought I could create the controls "on demand". I successfully created and drew it at the right spot with the code bellow:

    Code:
    	private: System::Void numericUpDown99_ValueChanged(System::Object^  sender, System::EventArgs^  e) 
    			 {
    				 String^ gbx_name;
    				 gbx_name = "groupBox2";
    
    				 GroupBox^ groupBox2;	//Cria novo GroupBox
    				 groupBox2 = (gcnew System::Windows::Forms::GroupBox());	//Seilá que porra é essa
    				 groupBox2->SuspendLayout();	
    				 tabPage2->Controls->Add(groupBox2);	//Adiciona o controle no tabPage2
    
    				 groupBox2->Location = System::Drawing::Point(128, 26);
    				 groupBox2->Name = L"groupBox2";
    				 groupBox2->Size = System::Drawing::Size(94, 400);
    				 groupBox2->TabIndex = 0;
    				 groupBox2->TabStop = false;
    				 groupBox2->Text = L"groupBox2";
    
    				 groupBox2->ResumeLayout(false);
    				 groupBox2->PerformLayout();
    			 }
    The problem is that I don't know how to create the controls with the names in sequence... For example, if I already created "groupBox2", how could I write a code that knows that and then it creates by itself "groupBox3" and on and on? We're talking of 96 groupboxes here...

    Any ideas? Was I clear on the explanation?

    Thanks a lot!
    Last edited by fernando306; December 27th, 2012 at 10:38 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured