//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "OnEndDrag.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
  ListBox1->Items->Add("Not");
  ListBox1->Items->Add("In");
  ListBox1->Items->Add("Alphabetical");
  ListBox1->Items->Add("Order");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ListBox1DragOver(TObject *Sender, TObject *Source,
      int X, int Y, TDragState State, bool &Accept)
{
   Accept = (Source->ClassNameIs("TLabel") && (((TLabel *)Source)->Caption == "Label1"));
}

// BeginExample: OnEndDrag
// Event: Controls.TControl.OnEndDrag

// BeginCode
/*
This code displays a message in a label named Status. The
message displayed depends on whether the dragged label
control was successfully dropped into and accepted by a
another control.
*/
void __fastcall TForm1::Label1EndDrag(TObject *Sender, TObject *Target, int X,
	  int Y)
{
  if (Sender->ClassNameIs("TLabel"))
  {
	AnsiString S = (dynamic_cast<TLabel *>(Sender))->Name + " was dropped and ";
	if (Target)
	  S = S + "accepted!";
	else
	  S = S + "rejected.";
	Status->Caption = S;
  }
}
// EndCode
// EndExample: OnEndDrag

// This OnDragDrop event handler implements the drop behavior.

void __fastcall TForm1::ListBox1DragDrop(TObject *Sender, TObject *Source,
      int X, int Y)
{


  if (Sender->ClassNameIs("TListBox") && Source->ClassNameIs("TLabel"))
  {
	TListBox *DestList = dynamic_cast<TListBox *>(Sender);
	DestList->Font = (dynamic_cast<TLabel *>(Source))->Font;
	DestList->Color = (dynamic_cast<TLabel *>(Source))->Color;
	DestList->DoubleBuffered = true;
	DestList->Color = clWindow;
  }
}
//---------------------------------------------------------------------------

