急求在FORM中用鼠标任意拖放ICON的方法,请给我EMAIL:TOPIC2000@SINA.COM(100分)

  • 主题发起人 主题发起人 leo.yuan
  • 开始时间 开始时间
L

leo.yuan

Unregistered / Unconfirmed
GUEST, unregistred user!
象操作 WIN9X 桌面那样……哈哈……好象很简单呀……

注意:1、给我发EMAIL的才能得分;
2、解决问题:50分;
3、创意分: 50分;

谢谢!
 
跟踪鼠标拖动的动作,记下鼠标的位置.
用一image对象表现图标,image.left:=x,image.top:=y
 
//用TListView把TListView放在form上,设定align:=alclient;
添加几个ListItem,设定大图标,ListView.viewstyle:=vsicon
下面是代码
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ImgList, ComCtrls;

type
TForm1 = class(TForm)
fghd: TListView;
ImageList1: TImageList;
procedure fghdDragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
procedure fghdDragDrop(Sender, Source: TObject; X, Y: Integer);
procedure fghdMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.fghdDragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
accept:=Source is TlistView
end;

procedure TForm1.fghdDragDrop(Sender, Source: TObject; X, Y: Integer);
var
PosPoint:TPoint;
begin
PosPoint.x:=x;
PosPoint.y:=Y;
(Source As TListView).Selected.SetPosition(PosPoint);
end;

procedure TForm1.fghdMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if button=mbleft then
begin
with sender as TListview do
begin
if GetItemAt(x,y)<>nil then
begindrag(false);
end;
end;
end;

end.
 
把icon放到image1中,在image1的OnMouseDown事件中记录鼠标的位置
lastx:=x;
lasty:=y;
在OnMouseMove事件中加入:
image1.left:=image1.left+x-lastx;
image1.top:=image1.top+y-lasty;

下面为源程序:

Unit Unit1;
Interface
Uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

Type
TForm1 = class(TForm)
procedure image1MouseDown(Sender: TObject; Button: TmouseButton;
Shift: TShiftState; X, Y: Integer);
procedure image1MouseMove(Sender: TObject; Shift: TshiftState; X,
Y: Integer);
Private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Ylx,yly:integer; //定义一个全局变量
Implementation
{$R *.DFM}
procedure TForm1.imageMouseDown(Sender: TObject; Button: TmouseButton;
Shift: TShiftState; X, Y: Integer);
Begin
Ylx:=x; //记录鼠标原来的坐标值
Yly:=y;
end;

procedure TForm1.imageMouseMove(Sender: TObject; Shift: TshiftState; X,
Y: Integer);
Begin
If ssleft in shift then begin //按下鼠标左键拖动image1
image1.left:=image1.left+x-ylx;
image1.top:=image1.top+y-yly;
end;
end;

end.
 
同意hubdog.
windows的桌面就是一个ListView
 
没什么好说的了
 
无话可说,倾向于www
 
可用 getcoursepos()获得鼠标所在位置参数是 tpoint;
var
weizhi:tpoint;
begin
getcoursepos(weizhi);
x:=weizhhi.x;
y:=weizhi.y;
然后设置 icon 的位置
 
各位大侠,我需要的是WIN9X的那种效果,比如选种了ICON会有阴影…………

(非MOUSE的定位问题呀……)

不过还是要感谢上面关心我提出问题的朋友们,谢谢了!!!!


Leo.yuan
 
试试这个?可惜效果不太好
DrawIconEx(
form1.Canvas.Handle, // handle to device context
image1.Left, // x-coordinate of upper left corner
image1.Top, // y-coordinate of upper left corner
image1.Picture.Icon.Handle, // handle to icon to draw
0, // width of the icon
0, // height of the icon
0, // index of frame in animated cursor
Getstockobject(GRAY_BRUSH), // handle to background brush
DI_IMAGE // icon-drawing flags
);
 
继续,近期结束。
 
多人接受答案了。
 

Similar threads

后退
顶部