Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Gráficos (https://www.clubdelphi.com/foros/forumdisplay.php?f=8)
-   -   TImage como boton (https://www.clubdelphi.com/foros/showthread.php?t=88711)

dfarias 20-07-2015 21:20:58

TImage como boton
 
Buenas tardes. Quiero hacer que un TImage al hacer click sobre el funcione como un boton. Es decir que se vea la accion de haberlo pulsado. Un cambio de imagen o un movimiento de ésta. Algo que le de animación pero la verdad que no se como.:confused:
Gracias anticipadas.

Casimiro Notevi 20-07-2015 21:42:20

Puedes dibujarle una sombra. Poner otra imagen. Cambiar el color de fondo, etc....
Hay muchas posibilidades, es cuestión de imaginación y escoger lo que más te guste.
¿Qué prefieres?

ecfisa 21-07-2015 01:09:45

Hola dfarias.

Otra alternativa es situar el TImage dentro de un Panel:
Código Delphi [-]
procedure TForm1.FormCreate(Sender: TObject);
begin
  Image1.Align  := alNone;
  Image1.Width  := Panel1.Width - 6;
  Image1.Height := Panel1.Height - 6;
  Image1.Stretch:= True;
  Image1.Left   := (Panel1.Width - Image1.Width) div 2;
  Image1.Top    := (Panel1.Height - Image1.Height) div 2;
end;

procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
  pnl: TPanel;
  img: TImage;
begin
  img := TImage(Sender);
  pnl := TPanel(img.Parent);
  pnl.BevelOuter := bvLowered;
  img.Width  := img.Width  - 2;
  img.Height := img.Height - 2;
end;

procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
  pnl: TPanel;
  img: TImage;
begin
  img := TImage(Sender);
  pnl := TPanel(img.Parent);
  pnl.BevelOuter :=  bvRaised;
  img.Width  := img.Width  + 2;
  img.Height := img.Height + 2;
end;

procedure TForm1.Image1Click(Sender: TObject);
var
  msg: TForm;
begin
  msg := CreateMessageDialog('ImageClick', mtCustom,[mbOk]);
  try
    msg.Left := Left + (Width - msg.Width) div 2;
    msg.Top  := Top  + (Height - msg.Height) div 2;
    msg.ShowModal;
  finally
    msg.Free;
  end;
end;

Efecto:


Saludos :)

dfarias 21-07-2015 10:25:51

Muchas gracias Ecfisa es lo que necesitaba.^\||/

dec 21-07-2015 16:32:31

Hola,

Por añadir otra posibilidad tal vez quieras echar un vistazo a los componentes Cindy para Delphi. Entre otros muchos componentes muy útiles encontrarás "super botones" que podrás personalizar muy mucho y también añadirles imágenes y fondos para diferentes "estados".


La franja horaria es GMT +2. Ahora son las 04:58:57.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi