unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls;type
TAnalysisControl = class(TCustomControl)
public
procedure MouseDown(Button : TMouseButton; Shift : TShiftState; X,Y : integer); override;
procedure MouseMove(Shift : TShiftState; X,Y : Integer); override;
procedure Paint; override;
end; TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;const
sizeBorder = 2; sc_SizeLeft = $F001; { these are the variations on the }
sc_SizeRight = $F002; { SC_SIZE value }
sc_SizeTop = $F003;
sc_SizeTopLeft = $F004;
sc_SizeTopRight = $F005;
sc_SizeBottom = $F006;
sc_SizeBottomRight = $F008;
sc_SizeBottomLeft = $F007;
sc_DragMove = $F012;implementationuses Winprocs;
{$R *.dfm}{ TAnalysisControl }procedure TAnalysisControl.MouseDown(Button: TMouseButton;
Shift: TShiftState; X, Y: integer);
begin
if Button = mbLeft then
begin
ReleaseCapture; if (X >= Width - sizeBorder) And NOT((Y <= sizeBorder) or (Y >= Height - sizeBorder)) then
Self.Perform(WM_SysCommand,sc_SizeRight,0)
else
if Not((X <= sizeBorder) or (X >= Width - sizeBorder)) And (Y <= sizeBorder) then
Self.Perform(WM_SysCommand,sc_SizeTop,0)
else
if (X <= sizeBorder) And (Y <= sizeBorder) then
Self.Perform(WM_SysCommand,sc_SizeTopLeft,0)
else
if (X >= Width - sizeBorder) and (Y <= sizeBorder) then
Self.Perform( WM_SysCommand, sc_SizeTopRight , 0 )
else
if Not((X <= sizeBorder) or (X >= Width - sizeBorder)) And (Y >= Height - sizeBorder) then
Self.Perform(WM_SysCommand,sc_SizeBottom,0)
else
if (Y >= Height - sizeBorder) And (X <= sizeBorder) then
Self.Perform(WM_SysCommand,sc_SizeBottomLeft,0)
else
if (Y >= Height - sizeBorder) and (X >= Width - sizeBorder) then
Self.Perform(WM_SysCommand, sc_SizeBottomRight, 0)
else
if Not((Y <= sizeBorder) or (Y >= Height - sizeBorder)) And (X <= sizeBorder) then
Self.Perform(WM_SysCommand,sc_SizeLeft,0)
else
begin
Self.Perform(WM_SysCommand,SC_DragMove,0);
end; end;end;procedure TAnalysisControl.MouseMove(Shift: TShiftState; X, Y: Integer);
begin
if (X <= sizeBorder) or (X >= Width - sizeBorder) then
begin
if (Y >= Height - sizeBorder) then
begin
if (X >= Width - sizeBorder) then
Cursor := crSizeNWSE
else
Cursor := crSizeNESW;
end
else
if (Y <= sizeBorder) then
begin
if (X >= Width - sizeBorder) then
Cursor := crSizeNESW
else
Cursor := crSizeNWSE;
end
else
Cursor := crSizeWE;
end
else
if (Y <= sizeBorder) or (Y >= Height - sizeBorder) then
begin
Cursor := crSizeNS;
end
else
Cursor := crDefault;end;procedure TAnalysisControl.Paint;
var
Rect: TRect;
info: string;
begin
Info := '测试程序';
With Canvas do
begin
Brush.Color := clWhite;
Brush.Style := bsSolid;
Rect := Self.GetClientRect;
FillRect(Rect);
//如何绘制居中的文字
OffSetRect(Rect, 0, 4);
DrawText(GetDc(Self.Handle), PChar(Info), Length(Info), Rect, DT_Center);
end;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
With TAnalysisControl.Create(Self) do
begin
Parent := Self;
Left := 20;
Top := 20;
Height := 90;
Width := 90;
end;
end;end.当我把继承关系修改为TAnalysisControl = class(TCustomGraphic)后,
为什么新的控件就不支持移动和改变大小操作了,请大家帮帮忙,看看是什么原因
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls;type
TAnalysisControl = class(TCustomControl)
public
procedure MouseDown(Button : TMouseButton; Shift : TShiftState; X,Y : integer); override;
procedure MouseMove(Shift : TShiftState; X,Y : Integer); override;
procedure Paint; override;
end; TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;const
sizeBorder = 2; sc_SizeLeft = $F001; { these are the variations on the }
sc_SizeRight = $F002; { SC_SIZE value }
sc_SizeTop = $F003;
sc_SizeTopLeft = $F004;
sc_SizeTopRight = $F005;
sc_SizeBottom = $F006;
sc_SizeBottomRight = $F008;
sc_SizeBottomLeft = $F007;
sc_DragMove = $F012;implementationuses Winprocs;
{$R *.dfm}{ TAnalysisControl }procedure TAnalysisControl.MouseDown(Button: TMouseButton;
Shift: TShiftState; X, Y: integer);
begin
if Button = mbLeft then
begin
ReleaseCapture; if (X >= Width - sizeBorder) And NOT((Y <= sizeBorder) or (Y >= Height - sizeBorder)) then
Self.Perform(WM_SysCommand,sc_SizeRight,0)
else
if Not((X <= sizeBorder) or (X >= Width - sizeBorder)) And (Y <= sizeBorder) then
Self.Perform(WM_SysCommand,sc_SizeTop,0)
else
if (X <= sizeBorder) And (Y <= sizeBorder) then
Self.Perform(WM_SysCommand,sc_SizeTopLeft,0)
else
if (X >= Width - sizeBorder) and (Y <= sizeBorder) then
Self.Perform( WM_SysCommand, sc_SizeTopRight , 0 )
else
if Not((X <= sizeBorder) or (X >= Width - sizeBorder)) And (Y >= Height - sizeBorder) then
Self.Perform(WM_SysCommand,sc_SizeBottom,0)
else
if (Y >= Height - sizeBorder) And (X <= sizeBorder) then
Self.Perform(WM_SysCommand,sc_SizeBottomLeft,0)
else
if (Y >= Height - sizeBorder) and (X >= Width - sizeBorder) then
Self.Perform(WM_SysCommand, sc_SizeBottomRight, 0)
else
if Not((Y <= sizeBorder) or (Y >= Height - sizeBorder)) And (X <= sizeBorder) then
Self.Perform(WM_SysCommand,sc_SizeLeft,0)
else
begin
Self.Perform(WM_SysCommand,SC_DragMove,0);
end; end;end;procedure TAnalysisControl.MouseMove(Shift: TShiftState; X, Y: Integer);
begin
if (X <= sizeBorder) or (X >= Width - sizeBorder) then
begin
if (Y >= Height - sizeBorder) then
begin
if (X >= Width - sizeBorder) then
Cursor := crSizeNWSE
else
Cursor := crSizeNESW;
end
else
if (Y <= sizeBorder) then
begin
if (X >= Width - sizeBorder) then
Cursor := crSizeNESW
else
Cursor := crSizeNWSE;
end
else
Cursor := crSizeWE;
end
else
if (Y <= sizeBorder) or (Y >= Height - sizeBorder) then
begin
Cursor := crSizeNS;
end
else
Cursor := crDefault;end;procedure TAnalysisControl.Paint;
var
Rect: TRect;
info: string;
begin
Info := '测试程序';
With Canvas do
begin
Brush.Color := clWhite;
Brush.Style := bsSolid;
Rect := Self.GetClientRect;
FillRect(Rect);
//如何绘制居中的文字
OffSetRect(Rect, 0, 4);
DrawText(GetDc(Self.Handle), PChar(Info), Length(Info), Rect, DT_Center);
end;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
With TAnalysisControl.Create(Self) do
begin
Parent := Self;
Left := 20;
Top := 20;
Height := 90;
Width := 90;
end;
end;end.当我把继承关系修改为TAnalysisControl = class(TCustomGraphic)后,
为什么新的控件就不支持移动和改变大小操作了,请大家帮帮忙,看看是什么原因
解决方案 »
- 怎样把一个浮点数存放到文件中?
- 在窗体右上角的关闭图标事件中用application.Terminate;终止整个程序的运行,可是报内存错误:不能为writenn
- 请问packed关键字有何用处
- 如何给别的程序发送控制消息
- *****6次金榜题名竟然6次退学 陕西贫困生玩弄爱心被曝光!!!!!!!!!!!!!!!!!
- 怎样可以去掉QuickRep打印预览中的打印机设置快捷键?
- Mediaplayer问题!望高手指导
- delphi7安装flatstyle后无法使用flatspineditinteger和flatspineditfloat
- Inherited & Abstract 我的理解,大家打分看看我的学习成绩~
- 你碰过这种情况吗?快来看看.......................................
- 这样第一个项目,应该要价多少,请兄弟们帮着定个价。。。
- 关于读取数据源的问题!
var oldPT: TPoint;
procedure TForm1.Label1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
GetCursorPos(oldPT);
end;procedure TForm1.Label1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var
pt: TPoint;
begin
GetCursorPos(pt);
if ssLeft in Shift then begin
Label1.Left := Label1.Left + pt.X - oldPT.X;
Label1.Top := Label1.Top + pt.Y - oldPT.Y;
end;
oldPT := pt;
end;
去GOOGLE里找一个就是了