PDA

Ver la Versión Completa : Fondo en formulario que no se ve


Ramsay
06-02-2016, 01:59:27
Hola , tengo un problema con un formulario , el problema es que no se ve el fondo , el codigo es :


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 :


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


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:

http://thumbs.subefotos.com/2a1d51cebacafd8d348eb7f5139ce024o.jpg (http://subefotos.com/ver/?2a1d51cebacafd8d348eb7f5139ce024o.png)

Pantalla completa

http://thumbs.subefotos.com/686705e7bca564ef055045174c430837o.jpg (http://subefotos.com/ver/?686705e7bca564ef055045174c430837o.png)