A
alaclp
Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;
interface
uses
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;
implementation
uses 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;
// Shape := stRectangle;
Height := 90;
Width := 90;
end;
end;
end.
请问为什么把继承关系改为 TAnalysisControl = class(TCustomGraphic)
就不行了呢?
如果我想制作可以移动及改变大小的图象空间,要实现上述效果该怎么做?
interface
uses
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;
implementation
uses 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;
// Shape := stRectangle;
Height := 90;
Width := 90;
end;
end;
end.
请问为什么把继承关系改为 TAnalysisControl = class(TCustomGraphic)
就不行了呢?
如果我想制作可以移动及改变大小的图象空间,要实现上述效果该怎么做?