Thanks for all you answers.
I have now gone back to my original project. This has a panel filling the form, on which I add at design time a number of panels, on which an image and labels are produced. I have used the main form's OnPaint event to add the images to the child panels and draw lines on the main panel.
When I run the program the main panel and its child panels appear, but the images and lines are missing. I have a menu item, Page Setup, which calls the OnPaint event and clicking this draws the images and lines. If I collapse the window and resize it the images and lines have gone and I have to click Page Setup again to retrieve them.
I have tried Mike's suggestions of TForm.Invalidate, TForm.Refresh and TForm.Repaint but none made any difference.
Below is my code:
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Menus,
ExtCtrls, StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Image1: TImage;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
MainMenu1: TMainMenu;
MnuPgSetup: TMenuItem;
MnuQuit: TMenuItem;
MnuFile: TMenuItem;
Panel1: TPanel;
PnlPage: TPanel;
procedure FormCreate(Sender: TObject);
procedure FormPaint(Sender: TObject);
procedure MnuQuitClick(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
LGO : TBitMap;
Panl: Array[1..10] of TPanel;
Derb: Array[1..10] of TLabel;
WClb: Array[1..10] of TLabel;
Nam: Array[1..10] of TLabel;
Stat: Array[1..10] of TLabel;
Posn: Array[1..10] of TLabel;
GapH, GapV, LineY, N, NumPnl, PanlWd, PanlHt, PicW, PicH,
PageHt, PageWd, TextY: Integer;
PgScale: Real;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
Top := 0;
Left := 0;
PageHt := 297;
PageWd := 210;
NumPnl := 10;
Height := Screen.Height - 28;
Width := Trunc(PageWd * Screen.Height / PageHt);
PnlPage.Top := 0;
PnlPage.Left := 0;
PnlPage.Height := Height - 17;
PnlPage.Width := ClientWidth;
PgScale := PnlPage.Height / PageHt;
GapH := Trunc(5 * PgScale);
GapV := 2 * GapH;
PanlWd := (PnlPage.Width - (2 * GapV)) Div 2;
PanlHt := (PnlPage.Height - (5 * GapV)) Div 5;
LineY := PanlHt Div 20;
LGO := TBitMap.Create;
LGO.LoadFromFile('DDWC Logo.bmp');
PicH := PanlHt Div 3;
PicW := PicH * LGO.Width Div LGO.Height;
For N := 1 to NumPnl Do
begin
Panl[N]:=TPanel.Create(self);
Panl[N].Parent:=PnlPage;
Panl[N].Left := GapH;
Panl[N].Top:= GapH + (N - 1) Div 2 * (GapV + PanlHt);
Panl[N].Width:= PanlWd;
Panl[N].Height:= PanlHt;
Panl[N].color:= clWhite;
Panl[N].BevelOuter := bvNone;
Panl[N].Canvas.Pen.color:= clBlack;
Panl[N].Font.Size := 14;
Derb[N]:=TLabel.Create(self);
Derb[N].Parent:=Panl[N];
Derb[N].Left := PicW;
Derb[N].Top := 5;
Derb[N].Autosize := False;
Derb[N].Width := PanlWd - PicW;
Derb[N].Height := 22;
Derb[N].Font.Name := 'Times New Roman';
Derb[N].Font.Size := 16;
Derb[N].Alignment := taCenter;
Derb[N].Caption := 'Derbyshire Dales';
WClb[N]:=TLabel.Create(self);
WClb[N].Parent:=Panl[N];
WClb[N].Left := PicW;
WClb[N].Top := Derb[N].Top + Derb[N].Height;
WClb[N].Autosize := False;
WClb[N].Width := PanlWd - PicW;
WClb[N].Height := 25;
WClb[N].Font.Name := 'Times New Roman';
WClb[N].Font.Size := 16;
WClb[N].Alignment := taCenter;
WClb[N].Caption := 'Woodcraft Club';
Nam[N]:=TLabel.Create(self);
Nam[N].Parent:=Panl[N];
Nam[N].Left := 0;
Nam[N].Top := WClb[N].Top + WClb[N].Height;
Nam[N].Autosize := False;
Nam[N].Width := PanlWd;
Nam[N].Height := 18;
Nam[N].Font.Name := 'Woodbadge';
Nam[N].Font.Size := 12;
Nam[N].Alignment := taCenter;
Nam[N].Font.color := clMaroon;
Nam[N].Caption := 'Joe Bloggs';
Stat[N]:=TLabel.Create(self);
Stat[N].Parent:=Panl[N];
Stat[N].Left := 0;
Stat[N].Top := Nam[N].Top + Nam[N].Height;
Stat[N].Autosize := False;
Stat[N].Width := PanlWd;
Stat[N].Height := 25;
Stat[N].Font.Name := 'kredit';
Stat[N].Font.Size := 12;
Stat[N].Alignment := taCenter;
Stat[N].Font.color := clGreen;
Stat[N].Caption := 'Club';
Posn[N]:=TLabel.Create(self);
Posn[N].Parent:=Panl[N];
Posn[N].Left := 0;
Posn[N].Top := Stat[N].Top + Stat[N].Height;
Posn[N].Autosize := False;
Posn[N].Width := PanlWd;
Posn[N].Height := 25;
Posn[N].Font.Name := 'kredit';
Posn[N].Font.Size := 12;
Posn[N].Font.color := clTeal;
Posn[N].Alignment := taCenter;
Posn[N].Caption := 'Member';
end;
// Invalidate;
// Refresh;
Repaint;
end;
procedure TForm1.FormPaint(Sender: TObject);
begin
PnlPage.Canvas.Pen.Color := clMedGray;
PnlPage.Canvas.Pen.Style := psDash;
For N := 1 to NumPnl Do
begin
if N Mod 2 = 0 then Panl[N].Left := 3 * GapH + PanlWd;
PnlPage.Canvas.Line(0, Panl[N].Top - 1, PnlPage.Width, Panl[N].Top - 1);
PnlPage.Canvas.Line(0, Panl[N].Top + PanlHt, PnlPage.Width, Panl[N].Top + PanlHt);
Panl[N].Canvas.StretchDraw(Bounds(5, 5, PicW + 5, PicH + 5), LGO);
end;
PnlPage.Canvas.Line(GapH - 1, 0, GapH - 1, PnlPage.Height);
PnlPage.Canvas.Line(PanlWd + GapH, 0, PanlWd + GapH, PnlPage.Height);
PnlPage.Canvas.Line(Panl[N].Left - 1, 0, Panl[N].Left - 1, PnlPage.Height);
PnlPage.Canvas.Line(2*PanlWd + 3*GapH, 0, 2*PanlWd + 3*GapH, PnlPage.Height);
end;
procedure TForm1.MnuQuitClick(Sender: TObject);
begin
Halt;
end;
END.
I have attached a picture of the initial screen and after clicking Page Setup.
Have I missed something?