如何使背景图片不被点中那?(100分)

  • 主题发起人 主题发起人 coolnet
  • 开始时间 开始时间
C

coolnet

Unregistered / Unconfirmed
GUEST, unregistred user!
我做了一个画流程图的东东,背景是一个大Image,在上面动态生成小的Image作为节点,
我为每个小Image都赋予了MouseDown和MouseUp事件,在背景Image中也有MouseDown和
MouseUp事件,但现在点击小Image时经常会触发背景Image的事件(也不是每次都触发,
有时又会触发小Image的事件),好像是大Image经常会覆盖到小Image上面,但我设了
大Image SendToBack了呀,如何才能让小Image不会被大Image覆盖?
 
小Image的Enabled不能为False;否则鼠标事件会被大Image收到
 
定义的事件响应怎么样?
贴个原码看看!!
 
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;

 
后退
顶部