To LeeChange:
小Image的Enable是True
原码如下:
其中imgCanvas就是背景Image,curModel的actList用于存储小Image
procedure TMainForm.imgCanvasClick(Sender: TObject);
var
HighestCode: Integer;
i: Integer;
nodeIndex: Integer;
begin
if OperateType = C_ACTTYPE then
begin
HighestCode := GetHighestActCode();
SetLength(curModel.actList,High(curModel.actList) + 2);
curModel.actList[High(curModel.actList)] := Tactivity.Create;
with curModel.actList[High(curModel.actList)] do
begin
actImg := TImage.Create(pnlMain);
actImg.Parent := pnlMain;
actImg.Tag := HighestCode + 1;
Left := ActLeft;
Top := ActTop;
actImg.Stretch := True;
actImg.OnMouseDown := ActMouseDown;//此处将小Image的MouseDown事件交由ActMouseDown处理
actImg.OnMouseUp := ActMouseUp; //此处将小Image的MouseUp事件交由ActMouseUp处理
actImg.Left := ActLeft;
actImg.Top := ActTop;
end;
RefreshCanvas;
Saved := False;
end;
end;
procedure TMainForm.ActMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
i: Integer;
begin
if Button = mbLeft then
begin
if (OperateType = C_LINETYPE) and (CurOperate <> C_NORMAL) then //画路径时
begin
if Not Drawing then
begin
Drawing := True;
imgCanvas.Canvas.MoveTo(X, Y);
Origin := Point(TImage(Sender).Left + TImage(Sender).Width,TImage(Sender).Top + TImage(Sender).Height);
MovePt := Origin;
BeginActID := TImage(Sender).Tag;
ReleaseCapture;
end;
end
end;
Saved := False;
end;
procedure TMainForm.ActMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
i, HighestCode: Integer;
begin
if Button = mbLeft then
begin
if (OperateType = C_LINETYPE) and Drawing then
begin
EndActID := TImage(Sender).Tag;
if BeginActID = EndActID then
begin
Drawing := False;
Exit;
end;
DrawBendLine(@imgCanvas, Origin, MovePt, pmNotXor);
if CheckDupTran(NewIntToStr(BeginActID),NewIntToStr(EndActID),@curModel) then
begin
Drawing := False;
Exit;
end;
MovePt := Point(TImage(Sender).Left,TImage(Sender).Top);
DrawBendLine(@imgCanvas,Origin, MovePt, pmNotXor);
Drawing := False;
HighestCode := GetHighestTranCode();
SetLength(curModel.tranList,High(curModel.tranList) + 2);
curModel.tranList[High(curModel.tranList)] := Ttransition.Create;
with curModel.tranList[High(curModel.tranList)] do
begin
tranCode := NewIntToStr(HighestCode + 1);
sourcePoint := Origin;
targetPoint := MovePt;
// SendMessage(pnlMain.Handle,WM_CAPTURECHANGED,0,pnlMain.Handle);
RefreshCanvas;
end;
end;
Saved := False;
end;