P
philips
Unregistered / Unconfirmed
GUEST, unregistred user!
下面的程序用到 2个Image 构件,有什么错误?
void __fastcall TForm1::FormCreate(TObject *Sender)
{
int i,y;
Image2->Visible = False;
Image1->Top = 0;
Image1->Left = 0;
Image1->Height = 3000;
Image2->Canvas->Brush->Style = bsClear;
for (i=1;i<Image1->Height; i++)
{
y=100*sin(i/180.0*3.1415);
Image1->Canvas->Pixels[y+300] = clRed;
}
}
void __fastcall TForm1::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 TForm1::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 TForm1::Image1MouseUp(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
int i,j;
if( bDrawing )
{
bDrawing = False;
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;
int itop = Image1->Top;
int 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(i=0;i<Image2->Height;i++)
for(j=0;j<Image2->Width;j++)
{
if( Image1->Canvas->Pixels[i+ileft][j+itop]!=clRed )
Image2->Canvas->Pixels[j]=clGreen;
else
Image2->Canvas->Pixels[j]=clRed;
}
Image2->Visible = True;
}
}
void __fastcall TForm1::Image2MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
StartPt.x = X;
StartPt.y = Y;
bDraging = True;
}
void __fastcall TForm1::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 TForm1::Image2MouseUp(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
bDraging = False;
}
它不能按预期的工作,请各位大侠救命!
我只有 5 分了。
void __fastcall TForm1::FormCreate(TObject *Sender)
{
int i,y;
Image2->Visible = False;
Image1->Top = 0;
Image1->Left = 0;
Image1->Height = 3000;
Image2->Canvas->Brush->Style = bsClear;
for (i=1;i<Image1->Height; i++)
{
y=100*sin(i/180.0*3.1415);
Image1->Canvas->Pixels[y+300] = clRed;
}
}
void __fastcall TForm1::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 TForm1::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 TForm1::Image1MouseUp(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
int i,j;
if( bDrawing )
{
bDrawing = False;
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;
int itop = Image1->Top;
int 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(i=0;i<Image2->Height;i++)
for(j=0;j<Image2->Width;j++)
{
if( Image1->Canvas->Pixels[i+ileft][j+itop]!=clRed )
Image2->Canvas->Pixels[j]=clGreen;
else
Image2->Canvas->Pixels[j]=clRed;
}
Image2->Visible = True;
}
}
void __fastcall TForm1::Image2MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
StartPt.x = X;
StartPt.y = Y;
bDraging = True;
}
void __fastcall TForm1::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 TForm1::Image2MouseUp(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
bDraging = False;
}
它不能按预期的工作,请各位大侠救命!
我只有 5 分了。