鼠标托动按钮而使它大小改变???
下一个问题可用ini文件或者注册表存储
下一个问题可用ini文件或者注册表存储
解决方案 »
- 视频抓图,还未解决。
- PageControl动态创建页面的问题:如何在Create Page时,Page上的控件就获得焦点,而不是在OoShow
- 求无文档API库ws2help.dll相关资料
- 请问如何在SQL查询分析器调试存储过程?
- 外在动态建立一条曲线(Tfastline)的时候 如何用代码写它的宽度 急! 还有.....
- 难道就没有DLL高手了吗??? 奇怪......(分可加呀!!!就算穷家当产)
- 那里有DEPHI 的下载和注册码啊?
- forgot的散分帖:请教大家一个感情问题——我跟她有可能发展下去吗?
- 我的窗口在任务栏上的图标不见了???
- 中程里面关于软件工程的部分多么?
- delphi到底有多好?我到底该不该改学delphi?
- "::"符号在程序中是什么意思?
在程序退出时将按钮的大小记录在临时的文件,下次启动时读取这个文件的记录下来的大小。
var
iWidth,iHeight:integer;
begin
iWidth := Width; iHeight := Height; //get form's width and height
//在注册表中设置两个键值,将高度和宽度保存
//在每次程序启动运行的时候,先到注册表中查FORM的高度和宽度,有值则设置FORM的高度和 宽度。end;
1.大小改变先注册一下组件:unit DdhSizer;interfaceuses
Classes, Windows, Messages, Controls, StdCtrls;const
sc_DragMove: Longint = $F012;type
TDdhSizeButton = class (TButton)
public
procedure WmNcHitTest (var Msg: TWmNcHitTest);
message wm_NcHitTest;
end; TDdhSizerControl = class (TCustomControl)
private
FControl: TControl;
FRectList: array [1..8] of TRect;
FPosList: array [1..8] of Integer;
public
constructor Create (AOwner: TComponent;
AControl: TControl);
procedure CreateParams (var Params: TCreateParams);
override;
procedure CreateHandle; override;
procedure WmNcHitTest (var Msg: TWmNcHitTest);
message wm_NcHitTest;
procedure WmSize (var Msg: TWmSize);
message wm_Size;
procedure WmLButtonDown (var Msg: TWmLButtonDown);
message wm_LButtonDown;
procedure WmMove (var Msg: TWmMove);
message wm_Move;
procedure Paint; override;
procedure SizerControlExit (Sender: TObject);
end;procedure Register;implementationuses
Graphics;// TDdhSizeButton methodsprocedure TDdhSizeButton.WmNcHitTest(var Msg: TWmNcHitTest);
var
Pt: TPoint;
begin
Pt := Point (Msg.XPos, Msg.YPos);
Pt := ScreenToClient (Pt);
if (Pt.x < 5) and (pt.y < 5) then
Msg.Result := htTopLeft
else if (Pt.x > Width - 5) and (pt.y < 5) then
Msg.Result := htTopRight
else if (Pt.x > Width - 5) and (pt.y > Height - 5) then
Msg.Result := htBottomRight
else if (Pt.x < 5) and (pt.y > Height - 5) then
Msg.Result := htBottomLeft
else if (Pt.x < 5) then
Msg.Result := htLeft
else if (pt.y < 5) then
Msg.Result := htTop
else if (Pt.x > Width - 5) then
Msg.Result := htRight
else if (pt.y > Height - 5) then
Msg.Result := htBottom
else
inherited;
end;// TDdhSizerControl methodsconstructor TDdhSizerControl.Create (
AOwner: TComponent; AControl: TControl);
var
R: TRect;
begin
inherited Create (AOwner);
FControl := AControl;
// install the new handler
OnExit := SizerControlExit;
// set the size and position
R := FControl.BoundsRect;
InflateRect (R, 2, 2);
BoundsRect := R;
// set the parent
Parent := FControl.Parent;
// create the list of positions
FPosList [1] := htTopLeft;
FPosList [2] := htTop;
FPosList [3] := htTopRight;
FPosList [4] := htRight;
FPosList [5] := htBottomRight;
FPosList [6] := htBottom;
FPosList [7] := htBottomLeft;
FPosList [8] := htLeft;
end;procedure TDdhSizerControl.CreateHandle;
begin
inherited CreateHandle;
SetFocus;
end;procedure TDdhSizerControl.CreateParams (var Params: TCreateParams);
begin
inherited CreateParams(Params);
Params.ExStyle := Params.ExStyle +
ws_ex_Transparent;
end;procedure TDdhSizerControl.Paint;
var
I: Integer;
begin
Canvas.Brush.Color := clBlack;
for I := 1 to 8 do
Canvas.Rectangle (FRectList [I].Left, FRectList [I].Top,
FRectList [I].Right, FRectList [I].Bottom);
end;procedure TDdhSizerControl.WmNcHitTest(var Msg: TWmNcHitTest);
var
Pt: TPoint;
I: Integer;
begin
Pt := Point (Msg.XPos, Msg.YPos);
Pt := ScreenToClient (Pt);
Msg.Result := 0;
for I := 1 to 8 do
if PtInRect (FRectList [I], Pt) then
Msg.Result := FPosList [I];
// if the return value was not set
if Msg.Result = 0 then
inherited;
end;procedure TDdhSizerControl.WmSize (var Msg: TWmSize);
var
R: TRect;
begin
R := BoundsRect;
InflateRect (R, -2, -2);
FControl.BoundsRect := R;
// setup data structures
FRectList [1] := Rect (0, 0, 5, 5);
FRectList [2] := Rect (Width div 2 - 3, 0,
Width div 2 + 2, 5);
FRectList [3] := Rect (Width - 5, 0, Width, 5);
FRectList [4] := Rect (Width - 5, Height div 2 - 3,
Width, Height div 2 + 2);
FRectList [5] := Rect (Width - 5, Height - 5,
Width, Height);
FRectList [6] := Rect (Width div 2 - 3, Height - 5,
Width div 2 + 2, Height);
FRectList [7] := Rect (0, Height - 5, 5, Height);
FRectList [8] := Rect (0, Height div 2 - 3,
5, Height div 2 + 2);
end;procedure TDdhSizerControl.SizerControlExit (Sender: TObject);
begin
Free;
end;procedure TDdhSizerControl.WmLButtonDown (var Msg: TWmLButtonDown);
begin
Perform (wm_SysCommand, sc_DragMove, 0);
end;procedure TDdhSizerControl.WmMove (var Msg: TWmMove);
var
R: TRect;
begin
R := BoundsRect;
InflateRect (R, -2, -2);
FControl.Invalidate; // repaint entire surface
FControl.BoundsRect := R;
end;// components registrationprocedure Register;
begin
RegisterComponents ('DDHB', [TDdhSizeButton]);
RegisterNoIcon ([TDdhSizerControl]);
end;end.(注DdhSizeButton可以直接用了,其它组件也要改变大小,可以跟DdhSizerControl关联起来实现,以下是使用例子)unit SizeForm;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, DdhSizer;type
TForm1 = class(TForm)
Button2: TButton;
CheckBox1: TCheckBox;
Edit1: TEdit;
Bevel1: TBevel;
Bevel2: TBevel;
DdhSizeButton1: TDdhSizeButton;
DdhSizeButton2: TDdhSizeButton;
procedure AttachSizer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}procedure TForm1.AttachSizer(Sender: TObject);
begin
TDdhSizerControl.Create (self, Sender as TControl);
end;2.位置的保存,可以用WriteComponent和ReadComponent来实现