Solved

Borland C++ Builder Add Control at Runtime

Posted on 2001-07-31
4
1,095 Views
Last Modified: 2008-02-26
I would like to add a TPanel control during runtime.  

In the Tform1 class:  
   TPanel tmp.  

In Tform1 constructor:
   tmp = new TPanel(Owner);
   tmp->Top = 100;
   tmp->Left = 100;
   tmp->Width = 100;
   tmp->Height = 100;
   tmp->Visible = true;

When the form is shown during runtime, there is no panel.  Also tried placing the code in the forms OnShow handler with no results.


0
Comment
Question by:lirtua
  • 2
4 Comments
 
LVL 6

Expert Comment

by:graham_k
ID: 6340268
I'll check at home tonight & post tomorow.   It looks ok, all that I can think of is that you might want to set tmp->Enabled = true and I would probably use tmp = new TPanel(Self); so tha the Form is the owner of teh new panel.

I'll let you know tomorrow at latest.

~graham();
0
 
LVL 2

Expert Comment

by:LoungeLizard
ID: 6342857
tmp = new TPanel(Form1);

should do the trick. The form is the owner of the panel, meaning that the panel should be displayed on the form.

Also, might a good idea to put it in the "OnShow" event, after the form has been contstructed and initialsed.
0
 
LVL 6

Accepted Solution

by:
graham_k earned 15 total points
ID: 6343423
this might sound silly, but I seem to dimly rememebr being stumpd by the same thing, and I reckon that you need to set the ->Parent property - which you would naturally assume the constrcutor would do.

So :

temp = new TPanel(self)
temp->Parent = self;

the only other thing which I do in addition to what you do is to set temp->FormStyle but I doubt if it is that.

Try setting ->Parent & let us know how it goes.

Good luck!

~graham();
0
 

Author Comment

by:lirtua
ID: 6520641
Thank you graham.  Here is the final source code that was placed in a menu item click event:

  tmp = new TPanel(frmMain);
  tmp->Parent = frmMain;
  tmp->Top = 5;
  tmp->Left = 5;
  tmp->Width = 5;
  tmp->Height = 5;
  tmp->Visible = true;

And in the form's class:

TPanel *tmp;


0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

775 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question