Results 1 to 5 of 5

Thread: Panel array op een Panel

  1. #1

    Panel array op een Panel

    Hallo allemaal,
    In onderstaande component wordt er op een panel een raster van andere panels gezet. Wanneer ik op een van de panels een button zet

    is deze gekoppeld met de ondergrond en niet met het panel. Hoe los je dit op, zodat de button op het andere panel blijft staan bij het vergroten van het Form.


    Met een vriendelijke groet, Frans

    Code:
    {==============================================================================
     Naam component    : lzgridpnl
     Maker             : 
     Copyright (c)     : Free ware
     Versie            : 01
     Datum             : 04-09-2018
     Doel              : 
     Componenten palet : LzSpraak
    
     Component         : Delphi en Lazarus
    
    
     Naam .PNG-bestand : TLzGridPanel.PNG       (Lazarus)
     Naam .LRS-bestand : LzGridPanel_icon.lrs   (Lazarus)
    
     Historie          : Datum       Omschrijving
                         ----------  ------------------------------------------------
                         04-09-2018  Start ontwikkeling component
    
    
    
    
         TPanel
           |
           +--- TLzGridPanel
    
    
    
    Permission is hereby granted, free of charge, to any person obtaining a copy 
    of this software and associated documentation files (the "Software"), to 
    deal in the Software without restriction, including without limitation the 
    rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 
    sell copies of the Software, and to permit persons to whom the Software is 
    furnished to do so, subject to the following conditions: 
    
    The above copyright notice and this permission notice shall be included in  
    all copies or substantial portions of the Software. 
    
    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 
    IN THE SOFTWARE. 
    
    
    ==============================================================================}
    
    
    UNIT lzgridpnl;
    
    {$IFDEF FPC}
     {$MODE Delphi}
    {$ENDIF}
    
    INTERFACE
    
    USES
    {$IFNDEF FPC}
      Windows,
    {$ELSE}
      LCLIntf,
      LCLType,
      LMessages,
      LResources,
    {$ENDIF}
      Messages,
      SysUtils,
      Variants,
      Classes,
      Graphics,
      Controls,
      Forms,
      Dialogs,
      StdCtrls,
      ExtCtrls;
    TYPE
      TLzGridPanel = CLASS(TPanel)
      PRIVATE     { Private declarations }
        Pnl: ARRAY[1..20, 1..20] OF TPanel;
      PROTECTED   { Protected declarations }
      PUBLIC      { Public declarations }
        CONSTRUCTOR Create(AOwner: TComponent); OVERRIDE;
        DESTRUCTOR Destroy; OVERRIDE;
        PROCEDURE Paint; OVERRIDE;
      PUBLISHED   { Published declarations }
        PROPERTY Hint;
        PROPERTY ShowHint;
        PROPERTY Tag;
      END;
    
    
    PROCEDURE Register;
    
    IMPLEMENTATION
    
    {==============================================================================
     Procedure : Register
     Maker     :
     Datum     : 04-09-2018
     Argument  :
     Resultaat :
     Doel      : Registreren van de component
    ==============================================================================}
    
    PROCEDURE Register;
    BEGIN
    {$IFDEF FPC}
      // Verwijder "//" in onderstaande regel als dit bestand is gemaakt
      //{$I LzGridPanel_icon.lrs}
    {$ENDIF}
      RegisterComponents('LzSpraak', [TLzGridPanel]);
    END;
    
    
    {==============================================================================
     Procedure : Create
     Maker     :
     Datum     : 04-09-2018
     Argument  : Sender: TObject
     Resultaat : Geen
     Doel      : Initiatie van de component
    ==============================================================================}
    
    CONSTRUCTOR TLzGridPanel.Create(AOwner: TComponent);
    VAR
      C, R: INTEGER;
    BEGIN
      INHERITED Create(AOwner);
      Height := 50;
      Width := 200;
      BorderWidth := 12;
      SetSubComponent(True);
      FOR R := 1 TO 20 DO
      BEGIN
        FOR C := 1 TO 20 DO
        BEGIN
          Pnl[C, R] := TPanel.Create(self);
          Pnl[C, R].Parent := self;
          Pnl[C, R].BevelInner := bvNone;
          Pnl[C, R].BevelOuter := bvNone;
          Pnl[C,R].SetSubComponent(True);
        END;
      END;
    END;
    
    {==============================================================================
     Procedure : Destroy
     Maker     :
     Datum     : 04-09-2018
     Argument  : Geen
     Resultaat : Geen
     Doel      :
    ==============================================================================}
    
    DESTRUCTOR TLzGridPanel.Destroy;
    BEGIN
      INHERITED Destroy;
    END;
    
    
    {==============================================================================
     Procedure : Paint
     Maker     :
     Datum     : 04-09-2018
     Argument  : Geen
     Resultaat : Geen
     Doel      : Tekenen component
    ==============================================================================}
    
    PROCEDURE TLzGridPanel.Paint;
    VAR
      C, R: INTEGER;
      H: INTEGER;
      W: INTEGER;
      Col: INTEGER;
      Row: INTEGER;
      Afstand: INTEGER;
    
    BEGIN
      ///Inherited Paint;
      Row := 2;
      Col := 5;
      Afstand := BorderWidth;
      H := ((Height - (Row + 1) * Afstand) DIV Row); // Panelhoogte van één panel op ondergrond Panel1
      W := ((Width - (Col + 1) * Afstand) DIV Col);
      FOR R := 1 TO Row DO
      BEGIN
        FOR C := 1 TO Col DO
        BEGIN
          Pnl[C, R].Height := H;
          Pnl[C, R].Top := R * Afstand + (R - 1) * H;
          Pnl[C, R].Width := W;
          Pnl[C, R].Left := C * Afstand + (C - 1) * W;
          Pnl[C, R].Color := clgray;
        END;
      END;
    END;
    
    {******************************************************************************}
    
    
    INITIALIZATION
      //RegisterClass(T...)
    
    END.

  2. #2
    Met onderstaande code voorkom je dat een component child een container wordt voor andere componenten. Of het werk in jou situatie en in Lazarus weet ik niet.

    Code:
    ControlStyle := ControlStyle - [csAcceptsControls];

  3. #3
    Luigi, dit werkt niet in Lazarus. M.a.w. het probleem is niet opgelost.

  4. #4
    Ik zie in je component nergens dat er een button wordt toegevoegd.
    Je wilt waarschijnlijk eerst de nieuwe component aan het form toevoegen en daarna de button.

    Wanneer ik met de hand een panel toevoeg aan een form, daarna het panel focus geef en panels toevoeg, worden de nieuwe panels child van de eerst toegevoegde panel.
    Wanneer ik nu een 'inner' panel selecteer en een button toevoeg, blijkt de button child te zijn van deze geselecteerde button.

    Mogelijk moet je eerst een inner panel focus geven voor je de button toevoegt.
    Òf je specificeert dat de parent van de button de inner panel (Pnl[n,m]) is.

    Verder: is het niet handig om de afmetingen van de inner panels al te berekenen bij de Create?

  5. #5
    MaartenW,
    De button wordt toegevoegd als deze component op het Form staat op de plaats van een van de panels. De afmetingen van de inner panels worden bepaald door het aantal rijen en kolommen en worden aangepast als het form een andere afmeting krijgt. Col en Row worden in de definitieve component instelbaar in de property editor.


    H.G Frans

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •