이런 방법이 있는줄 오늘 처음 알았습니다.
이방법은 MDI폼에만 배경넣는 방법만이 아니라
TCustomForm을 상속받은 모든폼에 배경넣는 방법입니다.
참조
http://www.delphitricks.com/source-code/forms/use_image_as_backgroung_of_form.html
위주소에 내용입니다.
procedure TForm1.FormCreate(Sender: TObject);
var
MyBitmap: TBitmap;
begin
MyBitmap:=TBitmap.Create;
MyBitmap.LoadFromFile('bg.bmp');
Form1.Brush.Bitmap:=MyBitmap;
end;
CBuilder 로 바꾸면?
void __fastcall TForm1::FormCreate(TObject *Sender)
{
Graphics::TBitmap *MyBitmap=new Graphics::TBitmap;
MyBitmap->LoadFromFile("bg.bmp");
Brush->Bitmap=MyBitmap;
}
이미지가 CilentRect보다 작으면 바둑판식으로 정렬됩니다.
간단히 작은 이미지를 폼의 배경에 바둑판식으로 정렬해 넣고 싶을때는 이방법이 아주 간편하며 유용할것 같습니다.
다른 TWinControl 은 안되고 폼만 되는 이유는
TCustomForm에서 WM_ERASEBKGND 메세지에 배경을 그려주는 루틴이 있어서 그런것 같습니다.
VCL TCustomForm.ClientWndProc 소스 일부분..
//--------------------------
WM_ERASEBKGND:
begin
FillRect(TWMEraseBkGnd(Message).DC, ClientRect, Brush.Handle);
{ Erase the background at the location of an MDI client window }
if (FormStyle = fsMDIForm) and (FClientHandle <> 0) then
begin
Windows.GetClientRect(FClientHandle, R);
FillRect(TWMEraseBkGnd(Message).DC, R, Brush.Handle);
end;
Result := 1;
end;
//--------------------------
응용1. 폼위에 TImage가 하나 올려져있을경우..
void __fastcall TForm1::FormCreate(TObject *Sender)
{
Brush->Bitmap=Image1->Picture->Bitmap;
}
응용2. 특정 Color로 패턴을 만들어서..
Graphics.hpp 에 AllocPatternBitmap 라는 함수가 있네요..
Brush->Bitmap =AllocPatternBitmap(clWhite, clRed);
추신 . MDI폼에 배경 넣기 다른방법들...
방법1.
http://cbuilder.borlandforum.com/impboard/impboard.dll?action=read&db=bcb_tip&no=357
방법2.
http://cbuilder.borlandforum.com/impboard/impboard.dll?action=read&db=bcb_tip&no=647
방법3.
http://cbuilder.borlandforum.com/impboard/impboard.dll?action=read&db=bcb_tip&no=746
그럼..
Brush.Bitmap.LoadFromFile('bg.bmp');
일케 쓰면 되네요.
그리고 소멸자에서
if Assigned(Brush.Bitmap) then Brush.Bitmap.Free;
를 해주셔야~~