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
Solved

Borland C++ Builder Add Control at Runtime

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C Language combined operators 28 114
Path to  STL Map header file 1 69
C++ :Change value from  DisableCMD registry 4 66
C++ mouse_event mouse look 7 96
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…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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.
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.

856 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