Solved

Top align problem

Posted on 2004-10-12
10
697 Views
Last Modified: 2010-04-05
I add into my component some buttons. My problem is that I wish to keep the order for alignement.

But1
But2
But3
...

When I create a new button and assign alTop I get:

But3
But2
But1

What to do?
0
Comment
Question by:ginsonic
10 Comments
 
LVL 7

Expert Comment

by:sftweng
ID: 12287493
Add them in reverse order?
0
 
LVL 9

Author Comment

by:ginsonic
ID: 12287851
No. Up is just a sample. I can add anytime, anyitem. In same time I'm interested how to move the But3 between but1 and but2.
0
 
LVL 7

Expert Comment

by:sftweng
ID: 12287896
At design time I've done reordering by switching alignment to alNone, repositioning and then switching back.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 9

Author Comment

by:ginsonic
ID: 12287957
I need on runtime!
0
 
LVL 17

Expert Comment

by:mokule
ID: 12288649
Hi,
what do You think about this.

procedure TForm1.Button1Click(Sender: TObject);
begin

Panel2.Align := alNone;
Panel3.Align := alNone;
Panel4.Align := alNone;

Panel2.Top := 0;
Panel3.Top := Panel2.Top+Panel2.Height;
Panel4.Top := Panel3.Top+Panel3.Height;

Panel2.Align := alTop;
Panel3.Align := alTop;
Panel4.Align := alTop;

end;

procedure TForm1.Button2Click(Sender: TObject);
begin

Panel2.Align := alNone;
Panel3.Align := alNone;
Panel4.Align := alNone;

Panel4.Top := 0;
Panel3.Top := Panel4.Top+Panel4.Height;
Panel2.Top := Panel3.Top+Panel3.Height;

Panel4.Align := alTop;
Panel3.Align := alTop;
Panel2.Align := alTop;

end;
0
 
LVL 9

Author Comment

by:ginsonic
ID: 12289991
Nope. This create a flickering.

One solution can be :

NewBut.Top:=MyVcl.Height;
NewBut.Align:=alTop;
0
 
LVL 7

Expert Comment

by:LRHGuy
ID: 12290634
This may be of some help...

http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_21058579.html

It concerns hiding/showing, but the idea of setting alNone and moving the panel off form seems to help.

Flicker can be controlled (possibly) with LockWindowUpdate:

LockWindowUpdate(Form.handle);
try
  // realign panels
finally
  LockWindowUpdate(0);
end;
0
 

Expert Comment

by:joncmora
ID: 12296230
var
  LastPos, I: Integer;
  NewButton: TButton;
begin
  NewButton := TButton.Create(Self);  //assuming self is your component and it owns all the components inside it
  NewButton.Visible := False;
  NewButton.Parent := Self;
  LastPos := 0;
  for I := Self.ComponentCount - 2 downto 0 do
  begin
    if Self.Components[I] is TButton then
    begin
      LastPos := TButton(Self.Components[I]).Top + TButton(Self.Components[I]).Height;
      Break;
    end;
  end;
  NewButton.Left := 0;
  NewButton.Top := LastPos;// + 2 {we can add a few more pixels just to make sure the new button is below the last one.};
  NewButton.Visible := True;
  NewButton.Align := alTop;
  NewButton.Caption := IntToStr(Self.ComponentCount);
end;
0
 
LVL 22

Accepted Solution

by:
Ferruccio Accalai earned 500 total points
ID: 12297071
hi ginsonic, i'd use a simple method:

the top of the new control shoulld be less than the bottom of the control on top, so the simplest way is:

procedure TForm1.AlignAfter(Control, After: TControl); //control is the control in creation, after the top control up the created
begin
   Control.Top := After.top+after.height-1; //to be sure that it's going between
   control.Align := alTop;
end;
now let's say that you have 3 panels with align altop

so

Panel1
Panel2
Panel3
using it as follows

procedure TForm1.Button1Click(Sender: TObject);
var
pnl: TPanel;
begin
pnl := TPanel.Create(self);
pnl.Caption := 'New Panel';
AlignAfter(Pnl,Panel2);
pnl.Parent := self;
end;

the order will be
Panel1
Panel2
New Panel
Panel3

really simply, or not?

F68 ;-)
0
 
LVL 9

Author Comment

by:ginsonic
ID: 12298584
Thanks to all for support!
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

803 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