Solved

Borland C++ Builder Add Control at Runtime

Posted on 2001-07-31
4
1,094 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

864 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now