Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I stop a TPanel containing controls? 1

Status
Not open for further replies.

Stretchwickster

Programmer
Apr 30, 2001
1,746
GB
Hi everyone,

I've just starting having a go at writing custom components. I have an issue that I need to resolve regarding TPanels. My custom component is inherited from a TPanel and it contains two components. I have this all working fine. However, if you drop the component on the form at design-time, it is possible to add further controls into the panel. I don't want this to be possible. Does anyone know of any solution?

Your help would be much appreciated!

Clive [infinity]
Ex nihilo, nihil fit (Out of nothing, nothing comes)
 
In the constructor, try changing the ControlStyle so it does not contain AcceptComponents (?)

Cheers
 
You are a genius Richard! I scoured loads of properties and didn't come across ControlStyle but it's done the trick - just what I wanted. Here's the code I used in the constructor of my new component:
Code:
  if csAcceptsControls in ControlStyle then
    ControlStyle := ControlStyle - [csAcceptsControls];
  FEdit1 := TEdit.Create(Self);
  with FEdit1 do
  begin
    Name := 'SubEdit1';
    Parent := Self;
    SetSubComponent(True);  // identifies FEdit1 as a subcomponent of Self
  end;
  FEdit2 := TEdit.Create(Self);
  with FEdit2 do
  begin
    Name := 'SubEdit2';
    Parent := Self;
    SetSubComponent(True);  // identifies FEdit2 as a subcomponent of Self
  end;
I wasn't sure if it would still allow me to add components after the ControlStyle line, but this works seamlessly when trying to add components at design-time.

Thanks again Richard! A star for you!


Clive [infinity]
Ex nihilo, nihil fit (Out of nothing, nothing comes)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top