D
dearmite
Unregistered / Unconfirmed
GUEST, unregistred user!
头文件和.cpp 文件都在下面。
不管我怎么弄,为什么都是黑黑一片。?
//---------------------------------------------------------------------------
#ifndef BackImageH
#define BackImageH
//---------------------------------------------------------------------------
#include <SysUtils.hpp>
#include <Controls.hpp>
#include <Classes.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
//---------------------------------------------------------------------------
class PACKAGE TBackImage : public TImage
{
public: // User declarations
private:
bool FGridStyle;
bool FXGridVisible;
bool FYGridVisible;
TColor FBackColor;
TColor FForeColor;
int FXGridWidth;
int FYGridWidth;
bool FXSnap;
bool FYSnap;
protected:
begin
_MESSAGE_MAP
// begin
_MESSAGE_MAP
// MESSAGE_HANDLER(WM_PAINT, TWMPaint, WMPaint)
//END_MESSAGE_MAP(TComponent)
// VCL_MESSAGE_HANDLER(WM_PAINT, , Repaint)
// VCL_MESSAGE_HANDLER(WM_PAINT, , RePaint)
// VCL_MESSAGE_HANDLER(WM_MOUSEMOVE, , OnMouseMove)
END_MESSAGE_MAP(TImage)
public:
void Draw();
__fastcall TBackImage(TComponent* Owner);
// virtual void __fastcall Repaint(void);
OnMouseMove(TObject * Sender, TShiftState Shift, int X, int Y);
virtual Repaint();
__property bool GridStyle = { read=FGridStyle, write=FGridStyle, default=true };
__property bool XGridVisible = { read=FXGridVisible, write=FXGridVisible, default=true };
__property bool YGridVisible = { read=FYGridVisible, write=FYGridVisible, default=true };
__property TColor BackColor = { read=FBackColor, write=FBackColor, default=clBlack };
__property TColor ForeColor = { read=FForeColor, write=FForeColor, default=clGreen };
__property int XGridWidth = { read=FXGridWidth, write=FXGridWidth, default=30 };
__property int YGridWidth = { read=FYGridWidth, write=FYGridWidth, default=30 };
__property bool XSnap = { read=FXSnap, write=FXSnap, default=false };
__property bool YSnap = { read=FYSnap, write=FYSnap, default=true };
__published:
};
//---------------------------------------------------------------------------
#endif
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "BackImage.h"
#pragma package(smart_init)
//---------------------------------------------------------------------------
// ValidCtrCheck is used to assure that the components createddo
not have
// any pure virtual functions.
//
static inline void ValidCtrCheck(TBackImage *)
{
new TBackImage(NULL);
}
//---------------------------------------------------------------------------
__fastcall TBackImage::TBackImage(TComponent* Owner)
: TImage(Owner)
{
}
//---------------------------------------------------------------------------
namespace Backimage
{
void __fastcall PACKAGE Register()
{
TComponentClass classes[1] = {__classid(TBackImage)};
RegisterComponents("Samples", classes, 0);
}
}
//---------------------------------------------------------------------------
void TBackImage:raw()
{
//---------------------------------------------------------------------------
this->Canvas->Brush->Color=FBackColor;
this->Canvas->FillRect(TRect(0,0,this->Width,this->Height));
this->Canvas->Pen->Color=FForeColor;
if (!this->GridStyle)
this->Canvas->Pen->Style=psDot ;
else
this->Canvas->Pen->Style=psSolid ;
if (FXGridVisible)
{ this->Canvas->Pen->Width=1;
for (int i =0;i<int ((this->Height)/FYGridWidth+1.5) ;i++)
{
this->Canvas->MoveTo (0,int(i * FYGridWidth));
this->Canvas->LineTo (this->Width ,int(i * FYGridWidth));
}
}
if (FYGridVisible)
{ this->Canvas->Pen->Width=2;
for (int i =0;i<int ((this->Width)/FXGridWidth+1.5) ;i++)
{
this->Canvas->MoveTo (i * FXGridWidth,0);
this->Canvas->LineTo (i * FYGridWidth,this->Height);
}
this->Canvas->Pen->Width=1;
}
}
//----------------------------------------------------
TBackImage::OnMouseMove(TObject * Sender, TShiftState Shift, int X, int Y)
{
//TODO: ageMouseMove(TObject *Sender, TShiftState Shift, int X, int Y)
TBevel *LevelX ,*LevelY;
//new LevelX=TBevelX();
// new LevelY=TBevelY();
LevelX->Parent=this->Parent;
LevelY->Parent=this->Parent;
LevelX->Left=this->Left;
LevelX->Top= this->Top;
LevelX->Width=this->Width;
LevelX->Height=1;
LevelY->Left=this->Left;
LevelY->Top=this->Top ;
LevelY->Width=2;
LevelY->Height=this->Height;
if (Shift.Contains(ssLeft))
{
if (X>0&&X<this->Width&&Y>0&&Y<this->Height)
{ //bool FXSnap;
bool FYSnap;
if (FXSnap) {if ((Y+6)/YGridWidth!=(Y-6)/YGridWidth)
LevelX->Top=this->Top+(int (Y+YGridWidth/2)/YGridWidth)*YGridWidth;
}
else
LevelX->Top= Y+this->Top;
if (FYSnap) {
if ((X+6)/XGridWidth!=(X-6)/XGridWidth)
LevelY->Left=this->Left+(int (X+XGridWidth/2)/XGridWidth)*XGridWidth;
}
else
LevelY->Left=X+this->Left;
}
}
TImage::OnMouseMove( Sender, Shift, X, Y);
return true;
}
TBackImage::Repaint(void)
{
Draw();
TImage::Repaint();
}
不管我怎么弄,为什么都是黑黑一片。?
//---------------------------------------------------------------------------
#ifndef BackImageH
#define BackImageH
//---------------------------------------------------------------------------
#include <SysUtils.hpp>
#include <Controls.hpp>
#include <Classes.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
//---------------------------------------------------------------------------
class PACKAGE TBackImage : public TImage
{
public: // User declarations
private:
bool FGridStyle;
bool FXGridVisible;
bool FYGridVisible;
TColor FBackColor;
TColor FForeColor;
int FXGridWidth;
int FYGridWidth;
bool FXSnap;
bool FYSnap;
protected:
begin
_MESSAGE_MAP
// begin
_MESSAGE_MAP
// MESSAGE_HANDLER(WM_PAINT, TWMPaint, WMPaint)
//END_MESSAGE_MAP(TComponent)
// VCL_MESSAGE_HANDLER(WM_PAINT, , Repaint)
// VCL_MESSAGE_HANDLER(WM_PAINT, , RePaint)
// VCL_MESSAGE_HANDLER(WM_MOUSEMOVE, , OnMouseMove)
END_MESSAGE_MAP(TImage)
public:
void Draw();
__fastcall TBackImage(TComponent* Owner);
// virtual void __fastcall Repaint(void);
OnMouseMove(TObject * Sender, TShiftState Shift, int X, int Y);
virtual Repaint();
__property bool GridStyle = { read=FGridStyle, write=FGridStyle, default=true };
__property bool XGridVisible = { read=FXGridVisible, write=FXGridVisible, default=true };
__property bool YGridVisible = { read=FYGridVisible, write=FYGridVisible, default=true };
__property TColor BackColor = { read=FBackColor, write=FBackColor, default=clBlack };
__property TColor ForeColor = { read=FForeColor, write=FForeColor, default=clGreen };
__property int XGridWidth = { read=FXGridWidth, write=FXGridWidth, default=30 };
__property int YGridWidth = { read=FYGridWidth, write=FYGridWidth, default=30 };
__property bool XSnap = { read=FXSnap, write=FXSnap, default=false };
__property bool YSnap = { read=FYSnap, write=FYSnap, default=true };
__published:
};
//---------------------------------------------------------------------------
#endif
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "BackImage.h"
#pragma package(smart_init)
//---------------------------------------------------------------------------
// ValidCtrCheck is used to assure that the components createddo
not have
// any pure virtual functions.
//
static inline void ValidCtrCheck(TBackImage *)
{
new TBackImage(NULL);
}
//---------------------------------------------------------------------------
__fastcall TBackImage::TBackImage(TComponent* Owner)
: TImage(Owner)
{
}
//---------------------------------------------------------------------------
namespace Backimage
{
void __fastcall PACKAGE Register()
{
TComponentClass classes[1] = {__classid(TBackImage)};
RegisterComponents("Samples", classes, 0);
}
}
//---------------------------------------------------------------------------
void TBackImage:raw()
{
//---------------------------------------------------------------------------
this->Canvas->Brush->Color=FBackColor;
this->Canvas->FillRect(TRect(0,0,this->Width,this->Height));
this->Canvas->Pen->Color=FForeColor;
if (!this->GridStyle)
this->Canvas->Pen->Style=psDot ;
else
this->Canvas->Pen->Style=psSolid ;
if (FXGridVisible)
{ this->Canvas->Pen->Width=1;
for (int i =0;i<int ((this->Height)/FYGridWidth+1.5) ;i++)
{
this->Canvas->MoveTo (0,int(i * FYGridWidth));
this->Canvas->LineTo (this->Width ,int(i * FYGridWidth));
}
}
if (FYGridVisible)
{ this->Canvas->Pen->Width=2;
for (int i =0;i<int ((this->Width)/FXGridWidth+1.5) ;i++)
{
this->Canvas->MoveTo (i * FXGridWidth,0);
this->Canvas->LineTo (i * FYGridWidth,this->Height);
}
this->Canvas->Pen->Width=1;
}
}
//----------------------------------------------------
TBackImage::OnMouseMove(TObject * Sender, TShiftState Shift, int X, int Y)
{
//TODO: ageMouseMove(TObject *Sender, TShiftState Shift, int X, int Y)
TBevel *LevelX ,*LevelY;
//new LevelX=TBevelX();
// new LevelY=TBevelY();
LevelX->Parent=this->Parent;
LevelY->Parent=this->Parent;
LevelX->Left=this->Left;
LevelX->Top= this->Top;
LevelX->Width=this->Width;
LevelX->Height=1;
LevelY->Left=this->Left;
LevelY->Top=this->Top ;
LevelY->Width=2;
LevelY->Height=this->Height;
if (Shift.Contains(ssLeft))
{
if (X>0&&X<this->Width&&Y>0&&Y<this->Height)
{ //bool FXSnap;
bool FYSnap;
if (FXSnap) {if ((Y+6)/YGridWidth!=(Y-6)/YGridWidth)
LevelX->Top=this->Top+(int (Y+YGridWidth/2)/YGridWidth)*YGridWidth;
}
else
LevelX->Top= Y+this->Top;
if (FYSnap) {
if ((X+6)/XGridWidth!=(X-6)/XGridWidth)
LevelY->Left=this->Left+(int (X+XGridWidth/2)/XGridWidth)*XGridWidth;
}
else
LevelY->Left=X+this->Left;
}
}
TImage::OnMouseMove( Sender, Shift, X, Y);
return true;
}
TBackImage::Repaint(void)
{
Draw();
TImage::Repaint();
}