MDI 子窗体 拖放时坐标问题(100分)(100分)

  • 主题发起人 主题发起人 lyh001
  • 开始时间 开始时间
L

lyh001

Unregistered / Unconfirmed
GUEST, unregistred user!
下面的 BCB程序在运行时,确定图象位置后,实际图形在不改变窗体滚动条时

shap1位置正确,可改变窗体滚动条后,shap1位置不正确,恳请各位指教。

把前面的程序进行简化,如下:

//---------------------------------------------------------------------
#include
#pragma hdrstop
#include "Child0form.h"
//---------------------------------------------------------------------
#pragma resource "*.dfm"

TPoint StartPt,EndPt;
bool bDrawing = False, bDraging = False;

//---------------------------------------------------------------------
__fastcall TfrmChild0::TfrmChild0(TComponent *Owner)
: TForm(Owner)
{
}

void __fastcall TfrmChild0::Image1MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
bDrawing = True; // begin bDrawing
Shape1->Visible = False;

StartPt = TPoint(X,Y);
EndPt = StartPt;

Image1->Canvas->Pen->Mode = pmNot;
Image1->Canvas->Pen->Color = clRed;
Image1->Canvas->Brush->Style =bsClear;
Image1->Canvas->Pen->Style = psDot;
}
//---------------------------------------------------------------------------

void __fastcall TfrmChild0::Image1MouseMove(TObject *Sender,
TShiftState Shift, int X, int Y)
{
if( bDrawing && ((EndPt.x != X)||(EndPt.y != Y)) )
{
Image1->Canvas->Rectangle(StartPt.x,StartPt.y, EndPt.x,EndPt.y);
Image1->Canvas->Rectangle(StartPt.x,StartPt.y, X,Y);
EndPt.x = X;
EndPt.y = Y;
}
}
//---------------------------------------------------------------------------

void __fastcall TfrmChild0::Shape1MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
StartPt.x = X;
StartPt.y = Y;
bDraging = True;
}
//---------------------------------------------------------------------------

void __fastcall TfrmChild0::Shape1MouseMove(TObject *Sender,
TShiftState Shift, int X, int Y)
{
if( bDraging )
{
Shape1->Left = Shape1->Left +X - StartPt.x;
Shape1->Top = Shape1->Top + Y - StartPt.y;
}
}
//---------------------------------------------------------------------------

void __fastcall TfrmChild0::Shape1MouseUp(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
bDraging = False;
}
//---------------------------------------------------------------------------
void __fastcall TfrmChild0::Image1MouseUp(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
if( bDrawing ) //松开鼠标
{
bDrawing = False;
Image1->Canvas->Rectangle(StartPt.x,StartPt.y, EndPt.x,EndPt.y);
Image1->Canvas->Pen->Mode = pmCopy;
Image1->Canvas->Brush->Style = bsClear;

Shape1->Height = abs(EndPt.y - StartPt.y);
Shape1->Width = abs(EndPt.x - StartPt.x);
int itop , ileft;
itop = Image1->Top ;
ileft = Image1->Left ;
Shape1->Top = StartPt.y-abs(itop);
Shape1->Left = StartPt.x-abs(ileft);
Shape1->Visible = True;
}
}

请各位大侠指教。

 
I want TO know.
 
怎么,又不行了?
 
我把程序发给你!
 
我已经给你发信了,我得回去了,实验室要关门了。明天见
 
我收到的文件可能传输有误,无法用winzip7 解开,能重发一次吗?
多谢!!
 
我的foxmail大概出问题了
实际只需作以下改动:

Shape1->Top = StartPt.y-abs(itop);
Shape1->Left = StartPt.x-abs(ileft);
 
我已解决此问题!多谢各位,尤其是 侠圣。
 
后退
顶部