Solved

How can I align my panel according to my button ?

Posted on 2008-06-26
8
262 Views
Last Modified: 2011-10-19
Hello guys,

as you can see in the picture I have a small panel with some box inside of it showing a legend of my color. But this panel only will be displayed if the user clicks on the last button. My need a way to show
this panel align that way, to the left side according to my buttom position. How can I do that through
rect or clientrect?

Did you get it?
Thanks
img1.jpg
0
Comment
Question by:hidrau
8 Comments
 
LVL 28

Expert Comment

by:2266180
ID: 21874862
when you show the panel, you will set the top, left and/or right properties of the panel to corespond to what you want.

for example:
panel.right:=button.right;
panel.top:=button.bottom+5;// leave 5 pixels between button and panel
panel.show;
0
 
LVL 10

Expert Comment

by:dinilud
ID: 21875160
Panel1.Top:=Button1.Top+Button1.Height+1;
 Panel1.Left:=Button1.Left+Button1.Width-Panel1.Width
0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 21875182
let's say you put the panel on an other form.
The reason ?
When you hit the button, the legend may de partially off screen

this routine starts with the legend window below the button aligned on the left side
if it would be partially invisible on the right or on the bottom it is moved
procedure ShowLegend(Sender: TObject);
var R: TRect;
  Offsets, Pt: TPoint;
  frm: TForm;
  btn: TButton;
begin
  frm := TForm(TComponent(Sender).Owner);
  btn := TButton(Sender);
  frmLegend := TfrmLegend.Create(frm);
  try
    R := Rect(0,0,frmLegend.Width,frmLegend.Height);
    Pt := frm.ClientToScreen(Point(0,0));
    OffsetRect(R, Pt.X, Pt.Y); // Move to Top left client of form
    OffsetRect(R, btn.Left, btn.Top); // Move to top left of button
    OffsetRect(R, 0, btn.Height); // Move below button
    if R.Right > Screen.Width then // Move to left if off screen on right
      OffsetRect(R, btn.Width - frmLegend.Width, 0);
    if R.Bottom > Screen.Height then // Move up if below screen
      OffsetRect(R, 0, 0 - btn.Height - frmLegend.Height);
    frmLegend.Top := R.Top;
    frmLegend.Left := R.Left;
    frmLegend.ShowModal;
  finally
    FreeAndNil(frmLegend);
  end;
end;

Open in new window

0
ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

 
LVL 1

Author Comment

by:hidrau
ID: 21875192
this work fine if my button is on the form

  suiPanel1.Left  := SpeedButton5.Left - suiPanel1.Width ;
  suiPanel1.Top   := SpeedButton5.Top  - suiPanel1.Height;
  suiPanel1.Show;

but this doesn't work if my speedbutton5 is in the other panel in the center of my form
0
 
LVL 1

Author Comment

by:hidrau
ID: 21875433
I didn't understand you example Geert_Gruwez to adapt it to my needs
0
 
LVL 10

Accepted Solution

by:
dinilud earned 500 total points
ID: 21875481
check my example


dfm
=====

object Form1: TForm1
  Left = 115
  Top = 114
  Width = 544
  Height = 375
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  OnCreate = FormCreate
  PixelsPerInch = 96
  TextHeight = 13
  object Panel2: TPanel
    Left = 48
    Top = 8
    Width = 353
    Height = 73
    Caption = 'Panel2'
    TabOrder = 1
    object Button1: TButton
      Left = 120
      Top = 16
      Width = 169
      Height = 41
      Caption = 'Button1'
      TabOrder = 0
    end
  end
  object Panel1: TPanel
    Left = 112
    Top = 144
    Width = 241
    Height = 57
    Caption = 'Panel1'
    TabOrder = 0
  end
end

Pas
=====

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls;

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    Panel2: TPanel;
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var pt:TPoint;
begin
  pt:=Button1.Parent.ClientToScreen(Point(Button1.Left,Button1.Top));
  pt:=ScreenToClient(pt);
  MoveWindow(Panel1.Handle,pt.X+Button1.Width-Panel1.Width,pt.Y+Button1.Height,
         Panel1.Width,Panel1.Height,True);
end;

end.
0
 
LVL 10

Expert Comment

by:dinilud
ID: 21875503
anyway i am leaving.
0
 
LVL 1

Author Closing Comment

by:hidrau
ID: 31470960
Thanks very much
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ddeman not working in activex 3 103
Dev Express grid collapse 2 44
tvirtualstringtree freeze when load too manny images 10 62
Dev express lookupcombo 3 27
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

770 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