如题
解决方案 »
- 同生缘
- 请问在delphi写代码的时候,怎么样整段的缩进左移右移?按Tab不行啊
- Dbgrid 快速显示,超急!!!分不够还可以加!
- 双声道MP3如何实现“原声”和“伴唱”(用TMEDIAPLAYER控伴)?
- 能否将服务断写成Windows NT中服务程序,如果能,如何写?客户段如何调用?
- 关于使用formula one模板的问题,求助!!!
- EnumSurfaces一个老的话题,可是没找到答案(delphi)
- 一个关于Listview 显示 缩略图的问题 见鬼了
- d5+listview的CustomDrawItem中系统资源为什么不能释放?
- 请问什么叫模拟鼠标和键盘事件?什么叫捕捉鼠标和键盘事件呢?
- DELPHI7有一个NOTEBOOK的控件我看别人的代码里有,可我找了半天也没找到!在那里呀?急!!!!!!!
- TClientSocket 的实现
设为True,然后再把TransparentColorValue改为clBlack,运行试试是不是这
个意思。
还有其他功能,自己看吧
在自动调整大小时,有些问题
==============================================================================={
David 修改的来自网络的控件。
可以实现:自动调整panel里的控件的位置和大小,添加背景
在自动调整大小时,有些问题,如果修改好,请给我一份
[email protected]}
unit AutoPnl;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls;type TPlacement = record
Left, Top, Width, Height: Integer;
end;
TFooClass = class(TControl); { needed to get at protected }{ font property } PIntArray = ^TRectArray;
TRectArray = array[0..4096] of TPlacement; TAutoPanel = class(TCustomPanel)
private
{ Private declarations }
FWallpaper: TPicture;
FTransparent: Boolean;
procedure SetTransparent(value: Boolean);
procedure WallpaperChanged(Sender: TObject);
procedure SetWallpaper(Value: TPicture);
protected
{ Protected declarations }
pWidth :Integer;
pHeight:Integer;
FAutoChildPosLeft : Boolean;
FAutoChildPosTop : Boolean;
FAutoChildWidth : Boolean;
FAutoChildHeight : Boolean;
PCtrlsCoordArr:PIntArray;
procedure Resize; override;
procedure Paint; override;
// procedure CreateParams(var Params: TCreateParams); override;
// procedure SetParent(AParent: TWinControl); override;
procedure DrawParentImage(Control: TControl; Dest: TCanvas);
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Loaded; override;
// procedure SetBounds(ALeft, ATop, AWidth, AHeight: Integer); override; published
property AutoChildPosLeft : Boolean read FAutoChildPosLeft write FAutoChildPosLeft default False;
property AutoChildPosTop : Boolean read FAutoChildPosTop write FAutoChildPosTop default False;
property AutoChildWidth : Boolean read FAutoChildWidth write FAutoChildWidth default False;
property AutoChildHeight : Boolean read FAutoChildHeight write FAutoChildHeight default False; property Align;
property Alignment;
property BevelInner;
property BevelOuter;
property BevelWidth;
property BorderWidth;
property BorderStyle;
property DragCursor;
property DragMode;
property Enabled;
property Caption;
property Color;
property Ctl3D;
property Font;
property Locked;
property ParentColor;
property ParentCtl3D;
property ParentFont;
property ParentShowHint;
property PopupMenu;
// property ParentShowHint default False;
property ShowHint default true;
property TabOrder;
property TabStop;
property Wallpaper: TPicture read FWallpaper write SetWallpaper;
property Transparent: Boolean read FTransparent write SetTransparent default false;
property Visible; property OnClick;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnResize;
property OnStartDrag;{$IFDEF VER120} {Borland Delphi 4.0 }
property Anchors;
property AutoSize;
property BiDiMode;
property Constraints;
property UseDockManager default True;
property DockSite;
property DragKind;
property FullRepaint;
property ParentBiDiMode; property OnCanResize;
property OnConstrainedResize;
property OnDockDrop;
property OnDockOver;
property OnEndDock;
property OnGetSiteInfo;
property OnStartDock;
property OnUnDock;
{$ENDIF} { Published declarations }
end;procedure Register;implementation procedure TAutoPanel.DrawParentImage(Control: TControl; Dest: TCanvas);
var
SaveIndex: Integer;
DC: HDC;
Position: TPoint;
begin
with Control do
begin
if Parent = nil then
Exit;
DC := Dest.Handle;
SaveIndex := SaveDC(DC);
{$IFDEF DFS_COMPILER_2}
GetViewportOrgEx(DC, @Position);
{$ELSE}
GetViewportOrgEx(DC, Position);
{$ENDIF}
SetViewportOrgEx(DC, Position.X - Left, Position.Y - Top, nil);
IntersectClipRect(DC, 0, 0, Parent.ClientWidth, Parent.ClientHeight);
Parent.Perform(WM_ERASEBKGND, DC, 0);
Parent.Perform(WM_PAINT, DC, 0);
RestoreDC(DC, SaveIndex);
end;
end;constructor TAutoPanel.Create(AOwner: TComponent);
begin
inherited;
FAutoChildPosLeft := False;
FAutoChildPosTop := False;
FAutoChildWidth := False;
FAutoChildHeight := False;
Caption:='';
pWidth := -1;
pHeight := -1;
PCtrlsCoordArr := nil;
FWallpaper := TPicture.Create;
FWallpaper.OnChange := WallpaperChanged;
ParentShowHint := False;
ShowHint := True;
// inherited Align := alTop;
end;
destructor TAutoPanel.Destroy;
begin
FreeMem(PCtrlsCoordArr);
FWallpaper.OnChange := nil;
FWallpaper.Free;
FWallpaper := nil;
inherited;
end;
var i:Integer;
begin
inherited Loaded;
if (csDesigning in ComponentState) then Exit; if (pWidth = -1) and (pHeight = -1) then begin
GetMem(PCtrlsCoordArr, ControlCount * sizeof(TRect));
for i := 0 to ControlCount - 1 do begin
PCtrlsCoordArr[i].Left := Controls[i].Left;
PCtrlsCoordArr[i].Top := Controls[i].Top;
PCtrlsCoordArr[i].Width := Controls[i].Width;
PCtrlsCoordArr[i].Height := Controls[i].Height;
end;
pWidth := Width;
pHeight := Height;
end;
end;procedure TAutoPanel.Resize;
var
I:Integer;
// Ph:integer;
begin
inherited;
{
TFooClass(Controls[i]).Font.Size :=
(NewFormWidth div OldFormWidth) *
TFooClass(Controls[i]).Font.Size;
}
if (csDesigning in ComponentState) then Exit;
try if (AutoChildPosLeft = false) and (AutoChildWidth = false) and
(AutoChildPosTop = false) and (AutoChildHeight = false) then Exit; for i := 0 to ControlCount - 1 do begin
if(AutoChildPosLeft = true) then
if (AutoChildWidth = true) then begin
Controls[i].Left := MulDiv (PCtrlsCoordArr[i].Left,Width,pWidth);
Controls[i].Width := MulDiv (PCtrlsCoordArr[i].Width,Width,pWidth); end
else
Controls[i].Left := Round(
PCtrlsCoordArr[i].Left * Width / pWidth +
((PCtrlsCoordArr[i].Width) * Width / pWidth -
(PCtrlsCoordArr[i].Width))/2
); if(AutoChildPosTop = true) then
if (AutoChildHeight = true) then begin
Controls[i].Top := MulDiv (PCtrlsCoordArr[i].Top,Height,pHeight);
Controls[i].Height := MulDiv (PCtrlsCoordArr[i].Height,Height,pHeight);
//TFooClass(Controls[i]).Font.Size:= Round((Height/pHeight)*TFooClass(Controls[i]).Font.Size);
end
else Controls[i].Top := Round(
PCtrlsCoordArr[i].Top * Height / pHeight +
((PCtrlsCoordArr[i].Height) * Height / pHeight - (PCtrlsCoordArr[i].Height))/2 ); end;
finally
end;
end;//=======
procedure TAutoPanel.WallpaperChanged(Sender: TObject);
begin
Invalidate;
end;procedure TAutoPanel.SetWallpaper(Value: TPicture);
begin
FWallpaper.Assign(Value);
end;procedure TAutoPanel.Paint;
var
XCnt, YCnt, X, Y: Integer;
BevelSize, SaveIndex: Integer;
Rect: TRect;
bitmap:tbitmap;
begin
inherited Paint;
if (FWallpaper.Graphic = nil) and FTransparent then
begin
// if not (csDesigning in ComponentState) then
// exit;
Bitmap := TBitmap.Create;
try
Bitmap.Height := ClientRect.Bottom;
Bitmap.Width := ClientRect.Right;
DrawParentImage(Self, Bitmap.Canvas);
canvas.CopyRect(ClientRect, Bitmap.canvas, ClientRect);
finally
Bitmap.free;
end;
end
else
begin
if (FWallpaper.Graphic <> nil) and (FWallpaper.Width > 0) and
(FWallpaper.Height > 0) then
begin
Rect := ClientRect;
BevelSize := BorderWidth;
if BevelOuter <> bvNone then Inc(BevelSize, BevelWidth);
if BevelInner <> bvNone then Inc(BevelSize, BevelWidth);
InflateRect(Rect, -BevelSize, -BevelSize);
SaveIndex := SaveDC(Canvas.Handle);
try
IntersectClipRect(Canvas.Handle, Rect.Left, Rect.Top,
Rect.Right -Rect.Left +1,
Rect.Bottom-Rect.Top +1 );
XCnt := (ClientWidth - 2 * BevelSize) div FWallpaper.Width;
YCnt := (ClientHeight - 2 * BevelSize) div FWallpaper.Height;
for X := 0 to XCnt do
for Y := 0 to YCnt do
Canvas.Draw(Rect.Left + X * FWallpaper.Width,
Rect.Top + Y * FWallpaper.Height, FWallpaper.Graphic);
finally
RestoreDC(Canvas.Handle, SaveIndex);
end;
end;
end;
end;//=======//透明
procedure TAutoPanel.SetTransparent(value: boolean);
begin
if ftransparent <> value then
begin
ftransparent := value;
invalidate;
end;
end;{procedure TAutoPanel.WMEraseBkgnd(var Msg: TMessage);
begin
if ftransparent then msg.result := 1
else inherited;
end;procedure TAutoPanel.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
params.exstyle := params.exstyle or WS_EX_TRANSPARENT;
end;procedure TAutoPanel.SetParent(AParent: TWinControl);
begin
inherited setparent(aparent);
if (aparent <> nil) and aparent.HandleAllocated
and (GetWindowLong(aparent.handle, GWL_STYLE) and WS_CLIPCHILDREN <> 0) then
setwindowlong(aparent.handle, GWL_STYLE,
GetWindowLong(aparent.handle, GWL_STYLE)
and not WS_CLIPCHILDREN);
end;procedure TAutoPanel.SetBounds(ALeft, ATop, AWidth, AHeight: Integer);
begin
invalidate;
inherited setbounds(aleft, atop, awidth, aheight);
end;}////procedure Register;
begin
RegisterComponents('Xac', [TAutoPanel]);
end;end.