L
lyh001
Unregistered / Unconfirmed
GUEST, unregistred user!
下面的 BCB程序在运行时,确定图象位置后,实际图形在不改变窗体滚动条时
shap1位置正确,可改变窗体滚动条后,shap1位置不正确,恳请各位指教。
//---------------------------------------------------------------------
#include <vcl.h>
#include <math.h>
#pragma hdrstop
#include "Child0form.h"
#include "dmform.h"
#include "Main.h"
//---------------------------------------------------------------------
#pragma resource "*.dfm"
TPoint StartPt,EndPt;
bool bDrawing = False, bDraging = False;
//---------------------------------------------------------------------
__fastcall TfrmChild0::TfrmChild0(TComponent *Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------
void __fastcall TfrmChild0::FormClose(TObject *Sender, TCloseAction &Action)
{
Action = caFree;
}
//---------------------------------------------------------------------
void __fastcall TfrmChild0::FormCreate(TObject *Sender)
{
Image1->Left = 0;
Image1->Top = 0;
Image1->Height = 3000;
Image1->Width = 796;
}
//---------------------------------------------------------------------------
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);
Shape1->Left = EndPt.x>StartPt.x ? StartPt.x: EndPt.x;
Shape1->Top = EndPt.y>StartPt.y ? StartPt.y: EndPt.y;
if( (Shape1->Width > 4) || (Shape1->Height > 2) )
{
MainForm->tbLeft->Enabled = True;
MainForm->tbRight->Enabled = True;
MainForm->tbUp->Enabled = True;
MainForm->tbDown->Enabled = True;
Shape1->Visible = True;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmChild0::Image1MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
if( Y>320 ) // 有效选择区
{
bDrawing = True; // begin bDrawing
Shape1->Visible = False;
MainForm->tbLeft->Enabled = False;
MainForm->tbRight->Enabled = False;
MainForm->tbUp->Enabled = False;
MainForm->tbDown->Enabled = 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)) && (Y>320) )
{
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;
}
//---------------------------------------------------------------------------
shap1位置正确,可改变窗体滚动条后,shap1位置不正确,恳请各位指教。
//---------------------------------------------------------------------
#include <vcl.h>
#include <math.h>
#pragma hdrstop
#include "Child0form.h"
#include "dmform.h"
#include "Main.h"
//---------------------------------------------------------------------
#pragma resource "*.dfm"
TPoint StartPt,EndPt;
bool bDrawing = False, bDraging = False;
//---------------------------------------------------------------------
__fastcall TfrmChild0::TfrmChild0(TComponent *Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------
void __fastcall TfrmChild0::FormClose(TObject *Sender, TCloseAction &Action)
{
Action = caFree;
}
//---------------------------------------------------------------------
void __fastcall TfrmChild0::FormCreate(TObject *Sender)
{
Image1->Left = 0;
Image1->Top = 0;
Image1->Height = 3000;
Image1->Width = 796;
}
//---------------------------------------------------------------------------
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);
Shape1->Left = EndPt.x>StartPt.x ? StartPt.x: EndPt.x;
Shape1->Top = EndPt.y>StartPt.y ? StartPt.y: EndPt.y;
if( (Shape1->Width > 4) || (Shape1->Height > 2) )
{
MainForm->tbLeft->Enabled = True;
MainForm->tbRight->Enabled = True;
MainForm->tbUp->Enabled = True;
MainForm->tbDown->Enabled = True;
Shape1->Visible = True;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmChild0::Image1MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
if( Y>320 ) // 有效选择区
{
bDrawing = True; // begin bDrawing
Shape1->Visible = False;
MainForm->tbLeft->Enabled = False;
MainForm->tbRight->Enabled = False;
MainForm->tbUp->Enabled = False;
MainForm->tbDown->Enabled = 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)) && (Y>320) )
{
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;
}
//---------------------------------------------------------------------------