Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Fondo en formulario que no se ve (https://www.clubdelphi.com/foros/showthread.php?t=89784)

Ramsay 06-02-2016 01:59:27

Fondo en formulario que no se ve
 
Hola , tengo un problema con un formulario , el problema es que no se ve el fondo , el codigo es :

Código Delphi [-]
procedure TForm1.btnTestClick(Sender: TObject);
var
  frm: TForm;
  myBmp: TBitmap;
  jImg: TJpegImage;
  Label1: TLabel;
begin
  try
    begin
      frm := TForm.Create(nil);
      frm.Caption := 'Title';
      frm.Width := 500;
      frm.Height := 300;

      jImg := TJpegImage.Create;
      myBmp := TBitmap.Create;

      jImg.LoadFromFile('c:/test.jpg');
      myBmp.Assign(jImg);
      frm.Brush.Bitmap := myBmp;

      Label1 := TLabel.Create(frm);
      Label1.Align := alClient;
      Label1.Alignment := taCenter;
      Label1.Layout := tlCenter;
      Label1.Parent := frm;
      Label1.Caption := 'hola mundo';
      Label1.Font.Color := clRed;
      Label1.Font.Size := 27;
      Label1.AutoSize := False;

      // frm.OnClose := CloseProc;

      frm.Show;
    end
  finally
    begin
      // frm.Free;
      jImg.Free;
      myBmp.Free;
    end;
  end;
end;

Eh logrado rastrear el error , el hecho de que no se vea el fondo es esta razon :

Código Delphi [-]
Label1.Parent := frm;

Pero si lo quito no se ve el label.

¿ Como soluciono este error ?

AgustinOrtu 06-02-2016 02:23:35

La propiedad Parent de un control indica cual es el control en donde debe ser renderizado el mismo; podrias decir que es la superficie en donde se debe dibujar

Luego, para visualizar una imagen en pantalla podes hacerlo mediante canvas, pero la forma mas practica es instanciar un control TImage, asi

Código Delphi [-]
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    OpenPictureDialog1: TOpenPictureDialog;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    FImage: TImage;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  if not OpenPictureDialog1.Execute then
    Exit;

  FImage.Picture.LoadFromFile(OpenPictureDialog1.FileName);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  FImage := TImage.Create(Self);
  FImage.Parent := Self;
  FImage.Align := alClient;
end;

end.

Salida:



Pantalla completa



La franja horaria es GMT +2. Ahora son las 00:59:08.

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