Solved

Top align problem

Posted on 2004-10-12
10
694 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
 
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now