![]() |
| | #1 | |
| Registered User Join Date: Feb 2008 Location: Australia
Posts: 41
| I'm using Visual C++ and am creating a Forms Application. How can you create a new control during runtime? For example, how could I create a new label in my Form during runtime when the user clicks a button or something? Thanks, Philipp
__________________ I program solely as a hobby so this is definitely not homework. Best thing that's been said to me: Quote:
| |
| starcatcher is offline | |
| | #2 |
| Jack of many languages Join Date: Nov 2007 Location: Katy, Texas
Posts: 1,929
| I'm sure you can. Put the "label create" call in its own function, and call that function whenever you need a new one. It should probably return the instance of the label created. Pass any variable information as parms to the function, like text for the label, position, etc. Todd
__________________ Mac and Windows cross platform programmer. Ruby lover. Memorable Quotes From Recent Posts: I can't remember. |
| Dino is offline | |
| | #3 | |
| Registered User Join Date: Feb 2008 Location: Australia
Posts: 41
| Here is what I tried: Code: this->label5=new Label(); this->label5->CreateControl(); this->label5->BackColor = System::Drawing::Color::Transparent; this->label5->Location = System::Drawing::Point(400,400); this->label5->Name = S"label5"; this->label5->Size = System::Drawing::Size(176,32); this->label5->Text = S"This is MY label!"; this->label5->BringToFront(); Code: private: System::Windows::Forms::Label * label5; Does anyone know how to actually get the control ONTO the form (so it can be seen)? Thanks, Philipp
__________________ I program solely as a hobby so this is definitely not homework. Best thing that's been said to me: Quote:
| |
| starcatcher is offline | |
| | #4 | |
| 3735928559 Join Date: Mar 2008
Posts: 662
| Quote:
| |
| m37h0d is offline | |
| | #5 | |
| Registered User Join Date: Feb 2008 Location: Australia
Posts: 41
| Thank you for the replies. After playing around a bit I worked out how to do it. Something like: Code: using namespace System::Windows::Forms; Label *MyLabel = new Label(); this::Controls::Add(Label); You can set all the other properties as well like I did when I first tried (only it would be simply 'MyLabel::...') If I run into any more troubles (which is very likely) I will post them under this thread to avoid creating a new one. Thanks again! Philipp
__________________ I program solely as a hobby so this is definitely not homework. Best thing that's been said to me: Quote:
| |
| starcatcher is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Profiler Valgrind | afflictedd2 | C++ Programming | 4 | 07-18-2008 09:38 AM |
| Silverlight 2 - creating controls | DavidP | C# Programming | 0 | 05-08-2008 02:07 PM |
| Creating Custom Controls | Grayson_Peddie | C# Programming | 1 | 12-29-2003 01:41 PM |
| Creating Controls on Window | samudrala_99 | Windows Programming | 4 | 01-30-2003 07:40 AM |
| BCBuilder Users! Help!! Runtime controls | Robert | C++ Programming | 0 | 03-24-2002 04:04 PM |