如何在运行期里,在图像周围出现可以调整大小的边框?(200分)

  • 主题发起人 whsuperboy
  • 开始时间
W

whsuperboy

Unregistered / Unconfirmed
GUEST, unregistred user!
用PaintBox时,在设计期可以看到它的四方形边框及黑点,鼠标移上去就能调整PaintBox的大小。
那么,在程序运行之后,我在PaintBox上画一个圆,如何实现当圆被选中时,在圆的四周出现边框和黑点,
让用户可以调整圆的大小?
这应该是图像软件的基本功能,可是我不会...
 
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;

type
TForm1 = class(TForm)
PaintBox1: TPaintBox;
procedure FormCreate(Sender: TObject);
procedure PaintBox1Paint(Sender: TObject);
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
R: TRect;
bSel: Boolean;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
PaintBox1.Width := 120; PaintBox1.Height := 120;
R.Top := 10; R.Left := 10; R.Right := 110; R.Bottom := 110;
bSel := False;
end;

procedure TForm1.PaintBox1Paint(Sender: TObject);
const
radii: Byte = 3;
begin
with PaintBox1.Canvas do
begin
Brush.Color := clWhite;
Ellipse(R);
if bSel then
begin
Brush.Color := clBlack;
Rectangle(R.Top - radii, (R.Left+R.Right) div 2 - radii, R.Top + radii, (R.Left+R.Right) div 2 + radii);
Rectangle(R.Bottom - radii, (R.Left+R.Right) div 2 - radii, R.Bottom + radii, (R.Left+R.Right) div 2 + radii);
Rectangle((R.Left+R.Right) div 2 - radii, R.Top - radii, (R.Left+R.Right) div 2 + radii, R.Top + radii);
Rectangle((R.Left+R.Right) div 2 - radii, R.Bottom - radii, (R.Left+R.Right) div 2 + radii, R.Bottom + radii);
end;
end;
end;

procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if bSel then
begin
bSel := False;
Invalidate;
end;
end;

procedure TForm1.PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if PtInRegion(CreateEllipticRgnIndirect(R), X, Y) then
begin
if not bSel then
begin
bSel := True;
Invalidate;
end;
end
else if bSel then
begin
bSel := False;
Invalidate;
end
end;

end.
 
有些明白了。唉,还得自己画。先记上100分。
 
你是不是还想改变圆的大小呀,我也可以帮你up
 
真是好人啊,帮帮忙,如何改变大小??
 
qianwt的方案好象只能出现黑框啊?大小呢?我感觉是不是作成控件就好办了。
 
顶部