Recent Comments

2012年8月15日 星期三

找出重疊的元件


.cpp
//---------------------------------------------------------------------------

#include
#pragma hdrstop

#include "Unit2.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm2 *Form2;
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm2::___TEST(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
int I;
TPoint pt;
TStringList *L = new TStringList;
GetCursorPos(&pt);
pt = this->ScreenToClient(pt);
for (I=0; I if (!Controls[I]->ClassNameIs("TPaintBox")){
continue;
}
if (!PtInRect(Controls[I]->BoundsRect , pt)){
continue;
}
L->Add(Controls[I]->Name);
}
ListBox1->Items->Text = L->Text;
delete L;
}
//---------------------------------------------------------------------------
void __fastcall TForm2::PaintBox1Paint(TObject *Sender)
{
TPaintBox  *tPbx =((TPaintBox *)Sender);
tPbx->Canvas->Rectangle(0,0,tPbx->Width,tPbx->Height);
}
//---------------------------------------------------------------------------
void __fastcall TForm2::Button1Click(TObject *Sender)
{
for (int I=0; I if (!Controls[I]->ClassNameIs("TPaintBox")){
continue;
}
((TPaintBox*)Controls[I])->OnMouseDown = ___TEST;
}
}
//---------------------------------------------------------------------------


====================================================
.h
//---------------------------------------------------------------------------

#ifndef Unit2H
#define Unit2H
//---------------------------------------------------------------------------
#include
#include
#include
#include
#include
//---------------------------------------------------------------------------
class TForm2 : public TForm
{
__published: // IDE-managed Components
TPaintBox *PaintBox1;
TPaintBox *PaintBox2;
TPaintBox *PaintBox3;
TListBox *ListBox1;
TButton *Button1;
void __fastcall PaintBox1Paint(TObject *Sender);
void __fastcall Button1Click(TObject *Sender);

private: // User declarations
void __fastcall ___TEST(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y);
public: // User declarations
__fastcall TForm2(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm2 *Form2;
//---------------------------------------------------------------------------
#endif

0 意見: