Карта сайта Kansoftware
НОВОСТИУСЛУГИРЕШЕНИЯКОНТАКТЫ
Разработка программного обеспечения
KANSoftWare

Изменить Z-порядок ваших контролов во время выполнения программы

Delphi , Компоненты и Классы , RTTI

Изменить Z-порядок ваших контролов во время выполнения программы

Оформил: DeeCo
Автор: http://www.swissdelphicenter.ch

{ 
  Sometimes you want to change the order of your controls during runtime. 
  Usually you only can send them all the way to the front (Control.BringToFront) or 
  send them all the way back (Control.SendToBack). 

  The following procedure will help you moving a control just one position for or back. 
  This is especially useful when using vector graphis or similar applications. 

  The procedure takes the control to be moved as the first parameter. 
  The direction is the second parameter (True brings the control one step up, 
  False sends it one step back). 

  Internally, this procedure works with SendToBack and BringToFront too, however, 
  it creates an order list first and pushes the other controls as well. 
}

 procedure ChangeControlZOrder(Sender: TObject; MoveUp: Boolean = True);
 var
   I, Curr: Integer;
   Control: TControl;
   List: TList;
 begin
   if Sender is TControl then
   begin
     // only components of type TControl and descendends 
    // work 
    Control := Sender as TControl;
     // has no parent, cannot move ;-) 
    if Control.Parent = nil then
       // quit 
      Exit;
     // determine position in z-order 
    Curr := -1;
     for I := 0 to Pred(Control.Parent.ControlCount) do
       if Control.Parent.Controls[I] = Sender then
       begin
         Curr := I;
         Break;
       end;
     if Curr < 0 then
       // position not found, quit 
      Exit;
     List := TList.Create;
     try
       if MoveUp then
       begin
         for I := Curr + 2 to Pred(Control.Parent.ControlCount) do
           // load other controls in group 
          List.Add(Control.Parent.Controls[I]);
         Control.BringToFront;
         for I := 0 to Pred(List.Count) do
           // move other controls to front, too 
          TControl(List[I]).BringToFront;
       end else begin
         for I := 0 to Curr - 2 do
           // load other controls in group 
          List.Add(Control.Parent.Controls[I]);
         Control.SendToBack;
         for I := Pred(List.Count) downto 0 do
           // move other controls to back, too 
          TControl(List[I]).SendToBack;
       end;
     finally
       List.Free;
     end;
   end;
 end;

Статья Изменить Z-порядок ваших контролов во время выполнения программы раздела Компоненты и Классы RTTI может быть полезна для разработчиков на Delphi и FreePascal.


Комментарии и вопросы


Ваше мнение или вопрос к статье в виде простого текста (Tag <a href=... Disabled). Все комментарии модерируются, модератор оставляет за собой право удалить непонравившейся ему комментарий.

заголовок

e-mail

Ваше имя

Сообщение

Введите код




Материалы статей собраны из открытых источников, владелец сайта не претендует на авторство. Там где авторство установить не удалось, материал подаётся без имени автора. В случае если Вы считаете, что Ваши права нарушены, пожалуйста, свяжитесь с владельцем сайта.



:: Главная :: RTTI ::


реклама



©KANSoftWare (разработка программного обеспечения, создание программ, создание интерактивных сайтов), 2007
Top.Mail.Ru Rambler's Top100
29.03.2024 17:40:31/0.033578872680664/0