Recent

Author Topic: TCaptionPanel  (Read 3627 times)

aducom

  • Full Member
  • ***
  • Posts: 155
    • http://www.aducom.com
TCaptionPanel
« on: March 10, 2015, 01:53:30 pm »
I'm looking for a TCaptionPanel. Found some old code, but is there a good existing component for that?

Zoran

  • Hero Member
  • *****
  • Posts: 1831
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: TCaptionPanel
« Reply #1 on: March 10, 2015, 01:59:50 pm »
I'm looking for a TCaptionPanel. Found some old code, but is there a good existing component for that?
For what?
TPanel has its Caption property. I guess you want something else, but I have no idea what it is.

aducom

  • Full Member
  • ***
  • Posts: 155
    • http://www.aducom.com
Re: TCaptionPanel
« Reply #2 on: March 10, 2015, 02:05:19 pm »
I mean a panel with a header part like a standard window. In Delphi there's a tcaptionpanel for that. Or theaderpanel.

Ocye

  • Hero Member
  • *****
  • Posts: 518
    • Scrabble3D
Re: TCaptionPanel
« Reply #3 on: March 10, 2015, 02:18:36 pm »
Just place another panel into your parent panel, make it as small you want and align it to top. Et voilá.
Lazarus 1.7 (SVN) FPC 3.0.0

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: TCaptionPanel
« Reply #4 on: March 10, 2015, 02:20:50 pm »
I've used this TPanel descendant occasionally. You could adapt it as needed.

Code: [Select]
unit captionPanel;

{$mode objfpc}{$H+}

interface

uses
  Classes, Graphics, ExtCtrls, Controls, LCLIntf;

type

  { TCaptionPanel }

  TCaptionPanel = class(TPanel)
  private
    FTextLayout: TTextLayout;
    procedure SetTextLayout(AValue: TTextLayout);
  protected
    procedure Paint; override;
  public
    constructor Create(TheOwner: TComponent); override;
  published
    property Layout: TTextLayout read FTextLayout write SetTextLayout default tlCenter;
  end;

implementation

{ TCaptionPanel }

procedure TCaptionPanel.SetTextLayout(AValue: TTextLayout);
begin
  if FTextLayout=AValue then Exit;
  FTextLayout:=AValue;
  Invalidate;
end;

procedure TCaptionPanel.Paint;
var
  ARect: TRect;
  TS : TTextStyle;
begin
  ARect := GetClientRect;
  if (BevelOuter <> bvNone) then
    Canvas.Frame3d(ARect, BevelWidth, BevelOuter);
  InflateRect(ARect, -BorderWidth, -BorderWidth);
  if (BevelInner <> bvNone) then
    Canvas.Frame3d(ARect, BevelWidth, BevelInner);
  if (Caption <> '') then
  begin
    TS := Canvas.TextStyle;
    TS.Alignment := BidiFlipAlignment(Self.Alignment, UseRightToLeftAlignment);
    if BiDiMode<>bdLeftToRight then
      TS.RightToLeft:= True;
    TS.Layout:= FTextLayout;
    TS.Opaque:= False;
    TS.Clipping:= False;
    TS.SystemFont:=Canvas.Font.IsDefault;
    if Enabled then
      Canvas.Font.Color := Font.Color
    else begin
      Canvas.Font.Color := clBtnHighlight;
      OffsetRect(ARect, 1, 1);
      Canvas.TextRect(ARect, ARect.Left, ARect.Top, Caption, TS);
      Canvas.Font.Color := clBtnShadow;
      OffsetRect(ARect, -1, -1);
    end;
    Canvas.TextRect(ARect,ARect.Left,ARect.Top, Caption, TS);
  end;
end;

constructor TCaptionPanel.Create(TheOwner: TComponent);
begin
  inherited Create(TheOwner);
  FTextLayout:=tlCenter;
end;

end.


aducom

  • Full Member
  • ***
  • Posts: 155
    • http://www.aducom.com
Re: TCaptionPanel
« Reply #5 on: March 10, 2015, 02:38:50 pm »
Tnx, this is the code I found, but it's from 2005. Will try it though. tnx.

BitBangerUSA

  • Full Member
  • ***
  • Posts: 183
Re: TCaptionPanel
« Reply #6 on: April 21, 2015, 07:15:24 pm »
Tnx, this is the code I found, but it's from 2005. Will try it though. tnx.

lol. 2005 a bad year for code?
Lazarus Ver 2.2.6 FPC Ver 3.2.2
Windows 10 Pro 64-bit

 

TinyPortal © 2005-2018