我看到网上许多地方对于MDI主窗体背景的设置都非常的复杂,说由于MDI主窗体程序的特殊性,所以在OnPaint事件里或利用image控件是不行的,可是我在MDI主窗体的OnPaint事件中这么写照样可以设置背景啊!难道网上和资料上都说错了吗?procedure TForm1.FormPaint(Sender: TObject);
Var
BitMap:TBitmap;
X,Y:Integer;
begin
X:=0;
Bitmap:=TBitmap.Create;
Bitmap.LoadFromFile(ExtractFileDir(Application.ExeName)+'\Back.bmp');
while (X<Width) do
Begin
Y:=0;
While (Y<Height) do
Begin
Canvas.Draw(x,y,bitmap);
Y:=Y+Bitmap.Height;
End;
X:=X+Bitmap.Width;
End;
End;
Var
BitMap:TBitmap;
X,Y:Integer;
begin
X:=0;
Bitmap:=TBitmap.Create;
Bitmap.LoadFromFile(ExtractFileDir(Application.ExeName)+'\Back.bmp');
while (X<Width) do
Begin
Y:=0;
While (Y<Height) do
Begin
Canvas.Draw(x,y,bitmap);
Y:=Y+Bitmap.Height;
End;
X:=X+Bitmap.Width;
End;
End;
TileImage:TImage;
2、编写Form1.OnCreate事件代码:
procedure TForm1.FormCreate(Sender: TObject);
begin
TileImage:=TImage.Create(Self);
TileImage.Picture.LoadFromFile('bg_green.bmp');
end;
3、编写Form1.OnPaint事件代码:
procedure TForm1.FormPaint(Sender: TObject);
var
PWidth,PHeight,X,Y: Integer;
begin
PWidth := TileImage.Picture.Bitmap.Width;
PHeight := TileImage.Picture.Bitmap.Height;
X := 0;
while X < Form1.Width do begin
Y := 0;
while Y < Form1.Height do begin
Form1.Canvas.Draw(X, Y, TileImage.Picture.Bitmap);
Y := Y + PHeight;
end;
X := X + PWidth;
end;
end;