Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi Bevel-Komponente die andere Steuerelemente akzeptiert? (https://www.delphipraxis.net/99489-bevel-komponente-die-andere-steuerelemente-akzeptiert.html)

Weazy 12. Sep 2007 23:57


Bevel-Komponente die andere Steuerelemente akzeptiert?
 
Ich suche eine Komponente, welche folgende Eigenschaften hat:

- akzeptiert andere Controls (z.b wie tpanel)
- ist transparent (z.b wie tbevel)
- hat eine align eigenschaft

ich probierte eine neue Komponente zu erstellen, welche von tbevel abgeleitet ist und habe dann bei controlstyle einfach csacceptcontrols hinzugefügt, dies hat jedoch nicht funktioniert... :wall:

SirTwist 13. Sep 2007 10:08

Re: Bevel-Komponente die andere Steuerelemente akzeptiert?
 
Es gibt ein recht umfangreiches Paket LMD Tools, in dem Ersatz für viele Standardkomponenten sind. Die größeren Packages sind kommerziell, es gibt aber eine "SE" als Freeware. Darin ist z.B. ein LMD Backpanel enthalten oder ein LMD SimplePanel. Zumindest ersteres hat Eigenschaften wie Transparent, Align und Bevel.

Gucks Dir mal an.

fs999 14. Sep 2007 08:22

Re: Bevel-Komponente die andere Steuerelemente akzeptiert?
 
Liste der Anhänge anzeigen (Anzahl: 1)
Hallo,

Der TBevel ist ein TGraphicControl der vom TControl ab. Um andere controls zu akzeptieren muss es vom TWinControl abstammen, dafür is der TPanel da, aber der ist nicht transparent.
Und hier ist die Lösung (als Beispiel) :
Delphi-Quellcode:
unit Unit1;

interface

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

type
  TMyPanel = class(TPanel)
  private
    procedure WMEraseBkgnd(var Msg: TWMEraseBkgnd); message WM_ERASEBKGND;
  protected
    procedure CreateParams(var Params: TCreateParams); override;
    procedure Paint; override;
  public
  published
  end;

  TForm1 = class(TForm)
    Image1: TImage;
    procedure FormShow(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    MyPanel: TMyPanel;
    Edit1: TEdit;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses Themes;

procedure TMyPanel.CreateParams(var Params: TCreateParams);
begin
  inherited CreateParams(Params);
  Params.ExStyle := Params.ExStyle or WS_EX_TRANSPARENT;
end;

procedure TMyPanel.WMEraseBkgnd(var Msg: TWMEraseBkgnd);
begin
  Msg.Result := 1;
end;

procedure TMyPanel.Paint;
const
  Alignments: array[TAlignment] of Longint = (DT_LEFT, DT_RIGHT, DT_CENTER);
  VerticalAlignments: array[TVerticalAlignment] of Longint = (DT_TOP, DT_BOTTOM, DT_VCENTER);
var
  Rect: TRect;
  TopColor, BottomColor: TColor;
//  FontHeight: Integer;
  Flags: Longint;

  procedure AdjustColors(Bevel: TPanelBevel);
  begin
    TopColor := clBtnHighlight;
    if Bevel = bvLowered then TopColor := clBtnShadow;
    BottomColor := clBtnShadow;
    if Bevel = bvLowered then BottomColor := clBtnHighlight;
  end;

begin
  Rect := GetClientRect;
  if BevelOuter <> bvNone then
  begin
    AdjustColors(BevelOuter);
    Frame3D(Canvas, Rect, TopColor, BottomColor, BevelWidth);
  end;
  {if not (ThemeServices.ThemesEnabled and (csParentBackground in ControlStyle)) then
    Frame3D(Canvas, Rect, Color, Color, BorderWidth)
  else}
    InflateRect(Rect, -BorderWidth, -BorderWidth);
  if BevelInner <> bvNone then
  begin
    AdjustColors(BevelInner);
    Frame3D(Canvas, Rect, TopColor, BottomColor, BevelWidth);
  end;
  with Canvas do
  begin
    {if not ThemeServices.ThemesEnabled or not ParentBackground then
    begin
      Brush.Color := Color;
      FillRect(Rect);
    end;}
    Brush.Style := bsClear;
    Font := Self.Font;
    Flags := DT_EXPANDTABS or DT_SINGLELINE or
      VerticalAlignments[VerticalAlignment] or Alignments[Alignment];
    Flags := DrawTextBiDiModeFlags(Flags);
    DrawText(Handle, PChar(Caption), -1, Rect, Flags);
  end;
end;


procedure TForm1.FormDestroy(Sender: TObject);
begin
  Edit1.Free;
  MyPanel.Free;
end;

procedure TForm1.FormShow(Sender: TObject);
begin
  MyPanel := TMyPanel.Create(Self);
  MyPanel.Parent := Self;
  MyPanel.Color := clRed;
  MyPanel.BorderWidth := 5;
  MyPanel.SetBounds(50, 50, ClientWidth-100, ClientHeight-100);
  MyPanel.BevelOuter := bvRaised;
  MyPanel.BevelInner := bvLowered;
  Edit1 := TEdit.Create(Self);
  Edit1.Parent := MyPanel;
  Edit1.Text := 'Hello there !';
  Edit1.SetBounds(50, 50, 150, 21);
end;

end.
Tada :wink:
In der Beilage kann man sehen wie es aussieht. Im Image1 muss natürlich ein Bild geladen werden...

mfG
Frederic


Alle Zeitangaben in WEZ +1. Es ist jetzt 10:38 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz