窗体图片背景(两种方法:设置Brush.Bitmap指向图片,别的控件也可以这样)
var Bitmap: TBitmap; procedure TForm1.FormCreate(Sender: TObject); begin Bitmap := TBitmap.Create; Bitmap.LoadFromFile('c:\temp\bg.bmp'); Self.Brush.Bitmap := Bitmap; end; procedure TForm1.FormDestroy(Sender: TObject); begin Bitmap.Free; end;
//效果图:
http://www.cnblogs.com/del/archive/2008/02/10/1066596.html
-------------------------------------------------------------------------------------------------------------------
WinAPI: CreatePatternBrush - 建立位图画刷
//声明: CreatePatternBrush( Bitmap: HBITMAP {位图句柄} ): HBRUSH; {返回画刷句柄}
//举例: procedure TForm1.FormPaint(Sender: TObject); var Bitmap: TBitmap; BrushHandle: HBRUSH; begin Bitmap := TBitmap.Create; Bitmap.LoadFromFile('c:\temp\bg.bmp'); BrushHandle := CreatePatternBrush(Bitmap.Handle); FillRect(Canvas.Handle, ClientRect, BrushHandle); DeleteObject(BrushHandle); end;
//效果图: