如何给窗体添加背景?

dlss 2000-03-16 02:58:00
如何给窗体添加背景?
...全文
373 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
dlss 2000-03-20
  • 打赏
  • 举报
回复
163的信箱我无法登录,可否将此控件往以下地址再给我发一份好吗?多谢.
jjc@dt.yanzhoucoal.com.cn
menxin 2000-03-20
  • 打赏
  • 举报
回复
只有如此简单?呵呵

.....
type
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure FormPaint(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
bmp:tbitmap;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
bmp:=TBitmap.Create;
bmp.LoadFromFile('c:\windows\tiles.bmp');
end;

procedure TForm1.FormPaint(Sender: TObject);
begin
Form1.Canvas.StretchDraw(Rect(0,0,Form1.Width,Form1.Height),bmp);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
bmp.free;
end;
.........

渤海海峡 2000-03-16
  • 打赏
  • 举报
回复
我给你发了一个,注意查收(在163信箱)
Brain 2000-03-16
  • 打赏
  • 举报
回复
that's true.
Judas 2000-03-16
  • 打赏
  • 举报
回复
IMAGE控件有一个STRETCH属性,设成TRUE,则图片可自动放大到与FORM相等。
Jean 2000-03-16
  • 打赏
  • 举报
回复
{***********************************************************}
{ }
{ Chou's Delphi VCL Extensions (CX Lib) }
{ }
{ Copyright (c) 1999 Jean-Christopher Chou }
{ }
{ ------------------------------------------------------- }
{ }
{ Class Name: TCxWallpaper }
{ Package: CwCtrls.dpk }
{ Writor: Jean-Christopher Chou }
{ Create Date: 1999-08-27 }
{ Description: Put it on your form and give it a bitmap }
{ then on runtime the form's background }
{ will be filled by a tiled bitmap. }
{ }
{***********************************************************}

unit CxWallpaper;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
TCxWallpaper = class(TComponent)
private
FForm: TForm;
FHandle: HWND;
FMargins: array [0..9] of Integer;
FClientInstance: TFarProc;
FPrevClientProc: TFarProc;
FBitmap: TBitmap;
procedure ClientWndProc(var Message: TMessage);
procedure SetBitmap(const Value: TBitmap);
protected
procedure Loaded; override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property Bitmap: TBitmap read FBitmap write SetBitmap;
end;

implementation

constructor TCxWallpaper.Create(AOwner: TComponent);
var
i: Integer;
begin
inherited Create(AOwner);
FBitmap := TBitmap.Create;
Randomize;
for i := 0 to 9 do
FMargins[i] := Random(100);
end;

destructor TCxWallpaper.Destroy;
begin
FBitmap.Free;
inherited Destroy;
end;

procedure TCxWallpaper.Loaded;
begin
inherited Loaded;
if not (csDesigning in ComponentState) then
begin
if not (Owner is TForm) then
raise Exception.Create('我只能在Form上用!')
else
begin
FForm := Owner as TForm;
if FForm.FormStyle = fsMDIForm then
FHandle := FForm.ClientHandle
else
FHandle := FForm.Handle;
FClientInstance := MakeObjectInstance(ClientWndProc);
FPrevClientProc := Pointer(GetWindowLong(FHandle, GWL_WNDPROC));
SetWindowLong(FHandle, GWL_WNDPROC, LongInt(FClientInstance));
end;
end;
end;

procedure TCxWallpaper.ClientWndProc(var Message: TMessage);
var
DC: HDC;
W, H, Mrg, Row, Col: Integer;
begin
with Message do
case Msg of
WM_ERASEBKGND:
if not FBitmap.Empty then
begin
DC := TWMEraseBkGnd(Message).DC;
W := FBitmap.Width;
H := FBitmap.Height;
for Row := 0 to FForm.ClientHeight div H do
begin
Mrg := FMargins[Row mod 10];
for Col := 0 to (FForm.ClientWidth + Mrg) div W + 3 do
BitBlt(DC, Col * W - Mrg, Row * H, W, H,
FBitmap.Canvas.Handle,
0, 0, SRCCOPY);
end;
Result := 1;
end;
else
Result := CallWindowProc(FPrevClientProc,
FHandle, Msg, wParam, lParam);
end;
end;

procedure TCxWallpaper.SetBitmap(const Value: TBitmap);
var
i: Integer;
begin
FBitmap.Assign(Value);
if not FBitmap.Empty then
begin
Randomize;
for i := 0 to 9 do
FMargins[i] := Random(FBitmap.Width);
end;
end;

end.
dlss 2000-03-16
  • 打赏
  • 举报
回复
可是我使用的背景图片比较小,窗体比较大,该如何处理?
蝈蝈俊 2000-03-16
  • 打赏
  • 举报
回复
用TImage控件,加入背景图片,只要保证TImage在最底层,用send to back.就可.
Judas 2000-03-16
  • 打赏
  • 举报
回复
在FORM上放一个IMAGE控件(在ADDITIONAL里),将其ALIGH属性定为ALCLIENT,在其
PICTURE属性中加入一幅背景画,搞定。

5,386

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧