//---------------------------------------------------------------------
#include <vcl.h>
#include <math.h>
#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::Image1MouseUp(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
int itop,ileft;
if( bDrawing )
{
bDrawing = False;
Image1->Canvas->Rectangle(StartPt.x,StartPt.y, EndPt.x,EndPt.y);
//Image1->Canvas->Rectangle(StartPt.x,StartPt.y, EndPt.x,EndPt.y);
Image1->Canvas->Pen->Mode = pmCopy;
Image1->Canvas->Pen->Color = clBlack;
Image1->Canvas->Brush->Style = bsClear;
itop = Image1->Top;
ileft = Image1->Left;
Image2->Height = abs(EndPt.y - StartPt.y);
Image2->Width = abs(EndPt.x - StartPt.x);
Image2->Left = (StartPt.x>EndPt.x ? EndPt.x :StartPt.x) +ileft;
Image2->Top = (StartPt.y>EndPt.y ? EndPt.y :StartPt.y) +itop;
for(int i=0;i<Image2->Height;i++)
for(int j=0;j<Image2->Width;j++)
{
if( Image2->Canvas->Pixels[j]==clRed )
Image2->Canvas->Pixels[j]=clGreen;
else
Image2->Canvas->Pixels[j]=clRed;
}
Image2->Visible = True;
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmChild0::Image1MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
Image2->Visible = False;
Image1->Canvas->Pen->Color = clWhite;
Image1->Canvas->Rectangle(StartPt.x,StartPt.y, EndPt.x,EndPt.y);
bDrawing = True;
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::Image2MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
StartPt.x = X;
StartPt.y = Y;
bDraging = True;
}
//---------------------------------------------------------------------------
void __fastcall TfrmChild0::Image2MouseMove(TObject *Sender,
TShiftState Shift, int X, int Y)
{ if( bDraging )
{
Image2->Left = Image2->Left +X - StartPt.x;
Image2->Top = Image2->Top + Y - StartPt.y;
Image2->Hint = "X:"+IntToStr(Image2->Left)+" Y:"+IntToStr(Image2->Top);
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmChild0::Image2MouseUp(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
bDraging = False;
}
//---------------------------------------------------------------------------
void __fastcall TfrmChild0::FormCreate(TObject *Sender)
{
int i,y;
for (i=1;i<Image1->Height; i++)
{
y=100*sin(i/180.0*3.1415);
Image1->Canvas->Pixels[y+200] = clRed;
}
}
//---------------------------------------------------------------------------
以上为我的代码,我欲选种部分曲线,用拖动的方法移动它。请大家帮忙改改。