问题如上:一个Panel上有一个Image用来显示一个BMP图片,我只是想设置让其可以移动位置,但是老做不到,单纯设置DragMode 设置为 dmAutomatic不能移动,同时将DragKind设置为dkDock可以移动,但是移动的时候多出了一个带叉的小窗口,并且图片可以被移动到任意位置。我希望图片只能在Panel范围里移动,并且周边不要带小窗口(我其实是想在Panel里同时载入很多的bmp图片)
以下是部分的简单代码:
Img: array[0..1000] of TImage;
。
。
。procedure TForm1.Button3Click(Sender: TObject);
begin
Img[Index] := TImage.Create(self);
//动态创建Timage
img[Index].Visible := True;
Img[Index].AutoSize := True; bitmap:=tbitmap.create;
opendialog1.filter:='bitmap file(*.bmp)|*.bmp';
if opendialog1.execute then
bitmap.loadfromfile(opendialog1.filename);
Img[Index].Picture.LoadFromFile(opendialog1.filename);
Img[Index].Parent:=Form2.Panel1;
// Img[Index].DragKind:=dkDock;
Img[Index].DragMode:=dmAutomatic; Index:=Index+1;
end;
以下是部分的简单代码:
Img: array[0..1000] of TImage;
。
。
。procedure TForm1.Button3Click(Sender: TObject);
begin
Img[Index] := TImage.Create(self);
//动态创建Timage
img[Index].Visible := True;
Img[Index].AutoSize := True; bitmap:=tbitmap.create;
opendialog1.filter:='bitmap file(*.bmp)|*.bmp';
if opendialog1.execute then
bitmap.loadfromfile(opendialog1.filename);
Img[Index].Picture.LoadFromFile(opendialog1.filename);
Img[Index].Parent:=Form2.Panel1;
// Img[Index].DragKind:=dkDock;
Img[Index].DragMode:=dmAutomatic; Index:=Index+1;
end;
解决方案 »
- DBGrid ,ADOQuery 相关
- 如何设置activeform参数
- 带参数的存储过程没法建立
- FORM1启动时,怎么样能让它隐藏,不显示?
- 用ADO连接Oracle能自动弹出输入密码的对话框吗?
- 嘴角急的冒泡! 报表问题 a component named QRStandardPreview already exist
- 如何判断汉字中的特殊符号如:'” ','。',',','《','》','!','¥','%',等。
- 在Delphi怎样向Execl导入一些数据.
- 不酷不要钱,很酷也不要钱,绝对。。。。
- 我用query.execsql,操作怎么不能立即提交?
- 怎样将显示的数据保存成Excel?
- 如何做拖拽FORM上的控件位置[在线等]
var
Form1: TForm1;
ox, oy: Integer;
bDrag: Boolean;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
begin
Panel1.DoubleBuffered := True;
end;procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
bDrag := True;
ox := X;
oy := Y;
end;procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if bDrag then
begin
Image1.Left := Image1.Left + X - ox;
Image1.Top := Image1.Top + Y - oy;
if Image1.Left <= - Image1.Width then Image1.Left := - Image1.Width + 2;
//其它几边你自己判断
end;
end;procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
bDrag := False;
end;
beginif Button=mbLeft then
begin
ReleaseCapture;
panel1.perform(WM_SysCommand, $F012, 0);
end;end;
panel1.perform -> image1.perform
procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
ReleaseCapture;
sendmessage(panel2.Handle,WM_NCLBUTTONDOWN,HTCAPTION,SC_MOVE+1);
end;这个我得慢慢研究下,先问下,panel才有句柄吗?Image没有 ?
Img: array[0..1000] of TImage;
Red: array[0..1000] of TPanel;……procedure TForm1.Button3Click(Sender: TObject);
begin
Img[Index] := TImage.Create(self);
//动态创建Timage
img[Index].Visible := True;
Img[Index].AutoSize := True;
Img[Index].Parent := Red[Index]; Red[Index] := TPanel.Create(self);
Red[Index].Parent := Form2.Panel1;
Red[Index].Visible := True;
Red[Index].Width:=Img[Index].Width;
Red[Index].Height:=Img[Index].Height; bitmap:=tbitmap.create;
opendialog1.filter:='bitmap file(*.bmp)|*.bmp';
if opendialog1.execute then
bitmap.loadfromfile(opendialog1.filename);
Img[Index].Picture.LoadFromFile(opendialog1.filename);
Img[Index].Parent:=Form2.Panel1;
// Img[Index].DragKind:=dkDock;
Img[Index].DragMode:=dmAutomatic;
Index:=Index+1;
end;这样怎么改成一个函数对每个 ImageMouseDown 事件都适应?即执行 xixuemao(俺可是㊣②㈧经儿滴人) 的那个 ReleaseCapture;
sendmessage(panel2.Handle,WM_NCLBUTTONDOWN,HTCAPTION,SC_MOVE+1);
在线盼答案
===================================
呵呵,你看一下继承关系就知道了。TImage是从TGraphicControl类继承来的,它是没有窗口句柄的,不能获得焦点。所以在下面放个panel就可以啦,嘿嘿^_^至于是不是动态创建都是一样的。下面是创建一个的,你循环就好了。事件可以用同一个。procedure TForm1.FormCreate(Sender: TObject);
begin
DoubleBuffered:= true;
image1.Parent:= Panel2;
image1.Align:= alClient;
image1.Stretch:= true;
end;
请问下通过AlphaBlendValue跟AlphaBlend 来设置窗口的透明,对fsMDIChild 来说是不是每用的啊?怎么我得不到想要的效果?有什么简单点的实现方法吗?