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!

Label, from one GroupBox to another 2

Status
Not open for further replies.

Pleco

Programmer
Mar 26, 2003
9
GB
Hi

I'm having trouble placing a label into a groupbox at runtime. I'll try to explain this the best I can.

I have a groupbox1 with a label inside it, I drag this label into groupbox2. Now I can perform this drag/drop process fine but where I'm having trouble is I want a button that when clicked will place the label back in it's original position in the first groupbox. I've tried placing the label back to it's original left/top properties (ie - Lbl1.Left := 15;)etc. However this places the label at left/top co-ordinates in within the groupbox it is presently in, so it stays at left = 15 in the second groupbox not first. I don't know how to get the label back into it's original groupbox.

I suspect I might be going about this the wrong way. Anyone here know of any ways to achieve this?

Thanks. :)
 
Try this and see what happens:
Code:
procedure TForm1.Button1Click(Sender: TObject);
begin
  if Label1.Parent = GroupBox1 then
    Label1.Parent := GroupBox2
  else
    Label1.Parent := GroupBox1;
end;
Notice that "Parent" is not the same as "Owner" which remains Form1 no matter which group box is the parent.
 
Bang on. That method worked in getting the label back in there. Thanks. [thumbsup2]

But I don't suppose you know how would I go about placing the label back in the exact same co-ordinates in the original GroupBox?
 
Easy! Just save the Top and Left properties and restore them after you move it back.
Code:
type
  TForm1 = class(TForm)
    :
    :
  private
    FSaveLeft: integer;
    FSaveTop: integer;
    :
    :
implementation

procedure TForm1.Button1Click(Sender: TObject);
begin
  if Label1.Parent = GroupBox1 then
    begin
      FSaveLeft := Label1.Left;
      FSaveTop := Label1.Top;
      Label1.Parent := GroupBox2;
      Label1.Left := 10;
      Label1.Top := 10;
    end
  else
    begin
      Label1.Parent := GroupBox1;
      Label1.Left := FSaveLeft;
      Label1.Top := FSaveTop;
    end;
end;


 
Thanks for the help. Much appreciated.[thumbsup2]
 
Glad I could help. But, I can't quite grasp just what it is you are trying to do. Moving a label around like that seems a little unusual to me. So just in case you haven't thought of it, you might consider having labels in both group boxes located wherever you want them and then just set their
Code:
 .Visible
properties according to which one you want to see, instead of moving one around.
 
Yeah I guess it may seem a little odd. It's more for usability. There's actually one groupbox containing several labels that can be dragged into a series of other groupboxes.
 
(C/S)houldn't you use TListBox-es for that?
- Drag and Drop are supported just fine
- Lists of items can be read from external sources
- Long lists scroll as needed

IMHO Labels are just spoiling resources on your system in this case.

HTH
Ath
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top