![]() |
|
#1
|
|||
|
|||
|
I want to create a deplhi application that
is capable of making the user able to drag and drop graphical objects like a line or something! I want to be able to create an OnDblClick event for this line after it is dragged in my form! How can I do so? |
|
#2
|
|||
|
|||
|
// Maybe this is what you want. If not email me.
// Reginaldo Ap. Rigo // virtual@alphanet.com.br // Hope it helps. unit DragnDrop; interface uses *Windows, Messages, SysUtils, Classes, *Graphics, Controls, Forms, Dialogs, *extctrls, StdCtrls; type *TForm1 = class(TForm) * *procedure FormCreate(Sender: TObject); * *procedure ImageClick(Sender: TObject); *private * *{ Private declarations } *public * *ImageNum : Integer; * *Image : TImage; * *//>>> * *// declare our DROPFILES message handler * *procedure AcceptFiles( var msg : TMessage ); * * * * * * *message WM_DROPFILES; * *//<<< *end; var *Form1: TForm1; implementation uses *// *// this unit contains certain *// functions that we'll be using *// *//>>> *ShellAPI; *//<<< {$R *.DFM} //>>> procedure TForm1.AcceptFiles( var msg : TMessage ); const *cnMaxFileNameLen = 255; var *i, *nCount * * : integer; *acFileName : array [ 0 .. cnMaxFileNameLen ] of char; begin *// find out how many files we're accepting *nCount := DragQueryFile( msg.WParam, * * * * * * * * * * * * * $FFFFFFFF, * * * * * * * * * * * * * acFileName, * * * * * * * * * * * * * cnMaxFileNameLen ); *// query Windows one at a time for the file name *for i := 0 to nCount-1 do *begin * *DragQueryFile( msg.WParam, i, * * * * * * * * * acFileName, cnMaxFileNameLen ); * *// do our thing with the acFileName * *if *StrUpper(PChar(ExtractFileExt( acFileName ))) ='.BMP' then * *// We handling just .bmp files for now. * *begin * * * Image := TImage.Create( Self ); * * * with Image do * * * begin * * * * AutoSize := true; * * * * Picture.LoadFromFile( acFileName ); * * * * Tag := ImageNum; * * * * OnClick := ImageClick; * * * * Parent := Form1; * * * * Left := ImageNum * 10; * * * * Top *:= ImageNum * 20; * * * end; * * * Inc( ImageNum ); * *end; *end; *// let Windows know that you're done *DragFinish( msg.WParam ); end; //<<< procedure TForm1.FormCreate(Sender: TObject); begin *// tell Windows that you're *// accepting drag and drop files *//>>> *DragAcceptFiles( Handle, True ); *//<< *ImageNum := 1; end; procedure TForm1.ImageClick(Sender: TObject); begin * *Form1.Caption := 'There was a click on the '+ IntToStr(( Sender as TImage ).Tag )+ ' image!'; end; end. |
![]() |
| Thread Tools | |
| Display Modes | |
|
|