想在指定的矩形范围内画矩形框 找会员积分管理软件
2楼: 画矩形框实现的办法是根据http://www.delphibbs.com/delphibbs/dispq.asp?lid=553056中doxpix所提的做法,实现后,我想在一个限定的矩形范围内画矩形,当所画的矩形移出矩形范围后让所画的矩形移到限定矩形范围里,让显示在外面的那部分不显示。或者也可以让它移到矩形范围里大小不变。其作用就是想让它不出限定矩形框范围。 如会员积分管理软件
3楼: 如果有不清楚的,请给我发消息到hody334@163.com,谢谢各位的帮助,我急着这个问题的解答。
4楼: 你限定的区域用一个panel代替,你要的矩形框用Shape代替!
拖动用
var
Form1: TForm1;
OldX,OldY:integer; //定义变量
implementation
{$R *.dfm}
procedure TForm1.Shape1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
OldX:=x;
OldY:=y;
end;
procedure TForm1.Shape1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if ssleft in shift then //按下鼠标左键
begin
Self.Left:=Self.Left+x-Oldx;
Self.Top:=Self.Top+y-Oldy;
//当然你可以在此处限止Shape1的Top和Left
end;
end;
5楼: 多谢,我这里有个问题就是我这个shape是动态生成的,不是放的shape控件。
6楼: 我是在form上放了一个image控件,这个控件控制范围,然后在mouseup中写了如下代码:
Image.canvas.Rectangle(Origin.x,Origin.y,MovePt.x,MovePt.y);
Lastpt := Point(x,y);//最后画的一个点
Drawing := False;
newshape(Origin, MovePt); //
SizeControl := TSizerControl.Create(self, shape);
fdragging:=false;
shape.BoundsRect:=frect;
Shape.Pen.Style := psDot;
Shape.Brush.Style := bsClear;
shape.Visible:=true;
procedure TForMain.newshape(TopLeft, BottomRight: TPoint);
begin
shape :=TShape.Create(self);
shape.parent := ScrollBox1 ;
if TopLeft.x > BottomRight.x then
Shape.Left := BottomRight.x
else
shape.Left := TopLeft.x;
if TopLeft.y > BottomRight.y then
shape.Top := BottomRight.y
else
shape.Top := TopLeft.y;
shape.Width := abs(BottomRight.x - TopLeft.x);
shape.Height := abs(BottomRight.y - TopLeft.y);
shape.Visible := true;
shape.Enabled := true;
end;
进销存软件版7楼: 我找到解决的办法了。
8楼: 把问题结了,谢谢royal!
9楼: 接受答案了.