Tendría un TPanel en mi aplicación pero con otro aspecto.
Para ello quiero una barra de título coloreada y la esquina superior redondeada al igual que en algunas interfaces de usuario como it ¿Conoces algún componente o biblioteca para él? (Preferencia de fuente abierta, pero no solo).
Intenté TJVCaptionPanel, está bien, pero necesita una esquina redondeada.Redondeado y titulado "TPanel" en Delphi 7
8
A
Respuesta
20
como esta?
unit CustomCaptionPanel;
interface
uses
Windows, SysUtils, Classes, Controls, Graphics;
type
TCustomCaptionPanel = class(TCustomControl)
private const
DEFAULT_BORDER_COLOR = $0033CCFF;
DEFAULT_CLIENT_COLOR = clWindow;
DEFAULT_BORDER_RADIUS = 16;
private
{ Private declarations }
FBorderColor: TColor;
FClientColor: TColor;
FBorderRadius: integer;
FCaption: TCaption;
FAlignment: TAlignment;
procedure SetBorderColor(BorderColor: TColor);
procedure SetClientColor(ClientColor: TColor);
procedure SetBorderRadius(BorderRadius: integer);
procedure SetCaption(const Caption: TCaption);
procedure SetAlignment(Alignment: TAlignment);
protected
procedure Paint; override;
{ Protected declarations }
public
constructor Create(AOwner: TComponent); override;
{ Public declarations }
published
{ Published declarations }
property Color;
property Caption read FCaption write SetCaption;
property Alignment: TAlignment read FAlignment write SetAlignment default taCenter;
property Font;
property BorderColor: TColor read FBorderColor write SetBorderColor default DEFAULT_BORDER_COLOR;
property ClientColor: TColor read FClientColor write SetClientColor default DEFAULT_CLIENT_COLOR;
property BorderRadius: integer read FBorderRadius write SetBorderRadius default DEFAULT_BORDER_RADIUS;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Rejbrand 2009', [TCustomCaptionPanel]);
end;
{ TCustomCaptionPanel }
constructor TCustomCaptionPanel.Create(AOwner: TComponent);
begin
inherited;
ControlStyle := [csAcceptsControls, csCaptureMouse, csClickEvents,
csSetCaption, csOpaque, csDoubleClicks, csReplicatable, csPannable];
FBorderColor := DEFAULT_BORDER_COLOR;
FClientColor := DEFAULT_CLIENT_COLOR;
FBorderRadius := DEFAULT_BORDER_RADIUS;
FAlignment := taCenter;
end;
procedure TCustomCaptionPanel.Paint;
var
r: TRect;
const
Alignments: array[TAlignment] of integer = (DT_LEFT, DT_RIGHT, DT_CENTER);
begin
inherited;
Canvas.Pen.Color := FBorderColor;
Canvas.Brush.Color := FBorderColor;
Canvas.Brush.Style := bsSolid;
Canvas.FillRect(Rect(FBorderRadius,
0,
ClientWidth - FBorderRadius,
FBorderRadius));
Canvas.Ellipse(Rect(0,
0,
2*FBorderRadius,
2*FBorderRadius));
Canvas.Ellipse(Rect(ClientWidth - 2*FBorderRadius,
0,
ClientWidth,
2*FBorderRadius));
Canvas.Brush.Color := FClientColor;
Canvas.Rectangle(Rect(0,
FBorderRadius,
ClientWidth,
ClientHeight));
Canvas.Font.Assign(Self.Font);
r := Rect(FBorderRadius, 0, ClientWidth - FBorderRadius, FBorderRadius);
Canvas.Brush.Style := bsClear;
DrawText(Canvas.Handle,
PChar(Caption),
length(Caption),
r,
DT_SINGLELINE or DT_LEFT or DT_VCENTER or DT_END_ELLIPSIS or Alignments[FAlignment]);
end;
procedure TCustomCaptionPanel.SetAlignment(Alignment: TAlignment);
begin
if FAlignment <> Alignment then
begin
FAlignment := Alignment;
Invalidate;
end;
end;
procedure TCustomCaptionPanel.SetBorderColor(BorderColor: TColor);
begin
if FBorderColor <> BorderColor then
begin
FBorderColor := BorderColor;
Invalidate;
end;
end;
procedure TCustomCaptionPanel.SetBorderRadius(BorderRadius: integer);
begin
if FBorderRadius <> BorderRadius then
begin
FBorderRadius := BorderRadius;
Invalidate;
end;
end;
procedure TCustomCaptionPanel.SetCaption(const Caption: TCaption);
begin
if not SameStr(FCaption, Caption) then
begin
FCaption := Caption;
Invalidate;
end;
end;
procedure TCustomCaptionPanel.SetClientColor(ClientColor: TColor);
begin
if FClientColor <> ClientColor then
begin
FClientColor := ClientColor;
Invalidate;
end;
end;
end.
Screenshot of the custom-caption panel control http://privat.rejbrand.se/customcaptionpanel.png
11
Si quieres la vuelta de la esquina de cualquier cosa que desee, intente esto:
procedure RoundCornerOf(Control: TWinControl) ;
var
R: TRect;
Rgn: HRGN;
begin
with Control do
begin
R := ClientRect;
rgn := CreateRoundRectRgn(R.Left, R.Top, R.Right, R.Bottom, 20, 20) ;
Perform(EM_GETRECT, 0, lParam(@r)) ;
InflateRect(r, - 4, - 4) ;
Perform(EM_SETRECTNP, 0, lParam(@r)) ;
SetWindowRgn(Handle, rgn, True) ;
Invalidate;
end;
end;
Cuestiones relacionadas
- 1. hacer una captura de subtítulos Delphi TPanel
- 2. Delphi, instaladores y Windows 7
- 3. Virus en Delphi 7
- 4. GetStackTrace en Delphi 7?
- 5. Delphi 2009 - cree un TPanel en tiempo de ejecución y cambie su color
- 6. Aplicación Delphi 7 y Microsoft Security Essentials
- 7. Delphi 7 tguid compare
- 8. Delphi 7 vista/windows 7 manifiesto
- 9. ¿Cómo detectar cuando el mouse se aleja de un TPanel en Delphi 6?
- 10. Delphi 7 enciende auto completar
- 11. Escuchando puerto serie en Delphi 7
- 12. Delphi 7 GIF en cuadro Dialog
- 13. Configuración del ícono EXE en Delphi 7
- 14. Trabajando con cadenas Unicode en Delphi 7
- 15. Comportamiento inesperado de Application.OnActivate en Delphi 7
- 16. Haciendo un TPageControl plano en Delphi 7
- 17. cálculo redondeado en cobol
- 18. Delphi 7 Windows Vista/7 Firewall Ubicaciones Excepción red
- 19. Delphi 7 - Decode Base64 Usando TIdDecoderMIME
- 20. ¿Algún consejo para aquellos que quieren actualizar de Delphi 7 (y hacia abajo) a Delphi 2010?
- 21. Función anti-aliasing simple para Delphi 7
- 22. redondeado UIScrollView Rendimiento
- 23. Delphi 7 - ¿Forzar InputBox solo a entero?
- 24. Ancho en píxeles de un texto/título en Delphi 7
- 25. haciendo una interfaz de asistente en delphi 7
- 26. Cómo deshabilita la ventana de la CPU en Delphi 7
- 27. Delphi 7 forma, no anclas de trabajo en Vista
- 28. Fuga de memoria con WMI en Delphi 7
- 29. Salidas de notificaciones de estilo de Windows 7 en Delphi
- 30. ¿Cómo recibir una solicitud http en Delphi 7?
excelente, funciona (con algunas modificaciones para D7) ... pero lo que es la licencia? – philnext
@philnext: Acabo de escribirlo. Puedes usarlo como quieras. –
¡Bien, gracias! Pero ¿por qué no lo pones en una 'fuente abierta' – philnext