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;
}
}
请各位大侠指教。
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;
}
}
请各位大侠指教。