Autor Beitrag
galagher
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2510
Erhaltene Danke: 44

Windows 10 Home
Delphi 10.1 Starter, Lazarus 2.0.6
BeitragVerfasst: Mo 25.10.04 16:38 
Hallo!
Das hier ist eine Panel-Komponente mit folgenden Zusatzfunktionen:

-> Ein Rahmen kann auf der Fläche dargestellt werden
-> Die Rahmenfarbe ist einstellbar
-> Caption kann nach oben und unten versetzt werden, 0 ist Mitte
-> Caption kann auch mehrzeilig sein
-> Das Panel kann "Schrauben" anzeigen (verspielt, ich weiss!) :D

//Edit: Statt "..Scew.." steht jetzt richtig "..Screw.." ! :mrgreen:
//Edit: Wenn jemand weiss, wie man nach Frame := True das PanelPlus "refresht", wäre mir geholfen! Zur Zeit muss man es nämlich so machen, damit auf dem PanelPlus liegende Komponenten wieder gezeichnet werden:
ausblenden Delphi-Quelltext
1:
2:
3:
 Panelplus1.FrameColor := clRed;
 Panelplus1.Frame := True;
 Panelplus1.Repaint;

Ich kann Repaint ja nicht in der Prozedur Paint aufrufen...

Wie dem auch sei - hier ein etwas optimierter Code:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
{****************************************************
 Eine Panel-Komponente mit zusätzlichen Funktionen.

                             galagher, Oktober 2004
*****************************************************}



unit PanelPlus;

interface

uses Types, SysUtils, Classes, ExtCtrls, Windows, Graphics, Controls;

type
  TPanelPlus = class(TPanel)
  private
    { Private-Deklarationen }
    FCaptionTop: Integer;
    FFrameColor: TColor;
    FFrame, FDrawScrew: Boolean;
  protected
    { Protected-Deklarationen }
    procedure Paint; override;
    procedure SetCaptionTop(Value: Integer);
    procedure SetFrameColor(Value: TColor);
    procedure SetFrame(Value: Boolean);
    procedure SetDrawScrew(Value: Boolean);
  public
    { Public-Deklarationen }
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    { Published-Deklarationen }
    property CaptionTop: Integer read FCaptionTop write SetCaptionTop;
    property Frame: Boolean read FFrame write SetFrame;
    property FrameColor: TColor read FFrameColor write SetFrameColor;
    property DrawScrew: Boolean read FDrawScrew write SetDrawScrew;
  end;

procedure Register;

implementation

{Zeichnen - wegen der Möglichkeit, die Caption nach oben oder unten zu}
{setzen, kann diese Prozedur nicht einfach vom Vorfahren übernommen werden}
procedure TPanelPlus.Paint;
const
  Alignments: array[TAlignment] of Longint = (DT_LEFT, DT_RIGHT, DT_CENTER);
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;

 Frame3D(Canvas, Rect, Color, Color, BorderWidth);
 if BevelInner <> bvNone then
 begin
  AdjustColors(BevelInner);
  Frame3D(Canvas, Rect, TopColor, BottomColor, BevelWidth);
 end;

 with Canvas do
 begin
  Brush.Color := Color;
  FillRect(Rect);
  Brush.Style := bsClear;
  Font := Self.Font;
  FontHeight := TextHeight('W');
  with Rect do
  begin
   Top := ((Bottom + Top) - FontHeight) div 2;
   Bottom := Top + FontHeight;
  end;

  Rect.Top := Rect.Top+FCaptionTop;
  Rect.Bottom := Rect.Bottom+Rect.Top;

  Flags := DT_EXPANDTABS or DT_VCENTER or Alignments[Alignment];
  Flags := DrawTextBiDiModeFlags(Flags);

  if FFrame then  {Einen Rahmen um das PanelPlus zeichnen}
  begin
   Pen.Color := FFrameColor;
   Pen.Width := BevelWidth+BorderWidth+2;
   Rectangle(BevelWidth+BorderWidth+1,BevelWidth+BorderWidth+1,ClientWidth-
    BevelWidth-BorderWidth-1,ClientHeight-BevelWidth-BorderWidth-1);
  end;

  DrawText(Handle, PChar(Caption), -1, Rect, Flags);
 end;

 if FDrawScrew then  {"Schrauben" zeichnen}
 begin
  if Height <= 80 then  {Nur 2 "Schrauben": links und rechts Mitte}
  begin
   Canvas.Pen.Color := $00A58F92;
   Canvas.Pen.Width := 1;
   Canvas.Brush.Color := $00D9CCCA;
   Canvas.FillRect(Types.Rect(6,Height div 2-3,12,Height div 2-2+5));
   Canvas.Ellipse(5, Height div 2-413, Height div 2+4);
   Canvas.MoveTo(7,Height div 2-2);
   Canvas.LineTo(11,Height div 2+2);
   Canvas.FillRect(Types.Rect(Width-6,Height div 2-3,Width-12,Height div 2-2+6));
   Canvas.Ellipse(Width-5, Height div 2-4, Width-13, Height div 2+4);
   Canvas.MoveTo(Width-8,Height div 2-2);
   Canvas.LineTo(Width-12,Height div 2+2);
  end
  else                  {4 "Schrauben": links oben/unten, rechts oben/unten}
  begin
   Canvas.Pen.Color := $00A58F92;
   Canvas.Pen.Width := 1;
   Canvas.Brush.Color := $00D9CCCA;
   Canvas.FillRect(Types.Rect(6,6,12,12));
   Canvas.Ellipse(5513,13);
   Canvas.FillRect(Types.Rect(Width-6,Height-6,Width-12,Height-12));
   Canvas.Ellipse(Width-5, Height-5, Width-13,Height-13);
   Canvas.FillRect(Types.Rect(Width-6,6,Width-12,12));
   Canvas.Ellipse(Width-55, Width-13,13);
   Canvas.FillRect(Types.Rect(6,Height-6,12,Height-12));
   Canvas.Ellipse(5, Height-513,Height-13);
   Canvas.MoveTo(7,7);
   Canvas.LineTo(11,11);
   Canvas.MoveTo(Width-8,Height-8);
   Canvas.LineTo(Width-12,Height-12);
   Canvas.MoveTo(Width-8,7);
   Canvas.LineTo(Width-12,11);
   Canvas.MoveTo(7,Height-8);
   Canvas.LineTo(11,Height-12);
  end;
 end;
end;

{------------------------------------------------------------------------------}

{Y-Position von Caption setzen}
procedure TPanelPlus.SetCaptionTop(Value: Integer);
begin
 FCaptionTop := Value;
 Paint;
end;

{------------------------------------------------------------------------------}

{Rahmenfarbe}
procedure TPanelPlus.SetFrameColor(Value: TColor);
begin
 FFrameColor := Value;
 Paint;
end;

{------------------------------------------------------------------------------}

{Rahmen Ja/Nein}
procedure TPanelPlus.SetFrame(Value: Boolean);
begin
 FFrame := Value;
 Paint;
end;

{------------------------------------------------------------------------------}

procedure TPanelPlus.SetDrawScrew(Value: Boolean);
begin
 FDrawScrew := Value;
 Paint;
end;

{------------------------------------------------------------------------------}

constructor TPanelPlus.Create(AOwner: TComponent);
begin
 inherited Create(AOwner);
 FFrameColor := Color;
end;

{------------------------------------------------------------------------------}

destructor TPanelPlus.Destroy;
begin
 inherited Destroy;
end;

{------------------------------------------------------------------------------}

procedure Register;
begin
 RegisterComponents('Samples', [TPanelPlus]);
end;

end.

_________________
gedunstig war's - und fahle wornen zerschellten karsig im gestrock. oh graus, es gloomt der jabberwock - und die graisligen gulpen nurmen!