Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Borland C++ Builder Add Control at Runtime

Posted on 2001-07-31
4
Medium Priority
?
1,108 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 60 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

730 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