在鼠标事件中自己改变image的位置就可以了。
解决方案 »
- 问个内存溢出的问题
- 如何获得DBGrid表中的一字段的总和?急呀!!!!!!!!!!
- ListView多选问题
- 关于Bold for Delphi的应用现状
- !!!!!!!!!!!!关于Delphi安装的怪问题
- 在线等待-100分(问几个很菜的问题,每个20分!!)
- DELPHI XE,E2010 Incompatible types: 'string' and 'Integer'错误
- 怎样从try的 except 处得到产生异常的代码的行号?
- 求真正的高手::判断当前活动窗口是不是IE,?这样为什么不行呢???快点好吗???
- 哪里有BDE下载?
- 哪里有象csdn这样的英语论坛?
- 求助!谁知道delphi6.163的serial number和authorization key!
//请参考
//Unit1.dfmobject Form1: TForm1
Left = 192
Top = 107
Width = 426
Height = 411
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Panel1: TPanel
Left = 0
Top = 41
Width = 418
Height = 343
Align = alClient
TabOrder = 0
object Image1: TImage
Left = 64
Top = 64
Width = 281
Height = 217
DragCursor = crUpArrow
Stretch = True
OnClick = Image1Click
OnMouseDown = Image1MouseDown
OnMouseMove = Image1MouseMove
OnMouseUp = Image1MouseUp
end
end
object Panel2: TPanel
Left = 0
Top = 0
Width = 418
Height = 41
Align = alTop
TabOrder = 1
object RadioButton3: TRadioButton
Left = 224
Top = 8
Width = 82
Height = 17
Caption = '缩小'
TabOrder = 0
OnClick = RadioButton3Click
end
object RadioButton2: TRadioButton
Left = 128
Top = 8
Width = 82
Height = 17
Caption = '放大'
TabOrder = 1
OnClick = RadioButton2Click
end
object RadioButton1: TRadioButton
Left = 24
Top = 8
Width = 82
Height = 17
Caption = '拖动'
Checked = True
TabOrder = 2
TabStop = True
OnClick = RadioButton1Click
end
object Button1: TButton
Left = 336
Top = 8
Width = 75
Height = 25
Caption = '载入图片'
TabOrder = 3
OnClick = Button1Click
end
end
object OpenPictureDialog1: TOpenPictureDialog
Left = 8
Top = 16
end
object Database1: TDatabase
SessionName = 'Default'
Left = 8
Top = 48
end
end//Unit1.pas
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, ExtDlgs, DB, DBTables;type
TForm1 = class(TForm)
Panel1: TPanel;
Image1: TImage;
OpenPictureDialog1: TOpenPictureDialog;
Database1: TDatabase;
Panel2: TPanel;
RadioButton3: TRadioButton;
RadioButton2: TRadioButton;
RadioButton1: TRadioButton;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure Image1Click(Sender: TObject);
procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure RadioButton1Click(Sender: TObject);
procedure RadioButton2Click(Sender: TObject);
procedure RadioButton3Click(Sender: TObject);
private
{ Private declarations }
FMouseDown: Boolean;
FOldPoint: TPoint;
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
if not OpenPictureDialog1.Execute then Exit;
Image1.Picture.LoadFromFile(OpenPictureDialog1.FileName);
Image1.AutoSize := True;
Image1.AutoSize := False;
Image1.Left := 0;
Image1.Top := 0;
end;procedure TForm1.Image1Click(Sender: TObject);
const
cOffset = 50;
begin
if RadioButton2.Checked then begin //放大
Image1.Width := Image1.Width + cOffset;
Image1.Height := Image1.Height + cOffset;
Exit;
end;
if RadioButton3.Checked then begin //放大
Image1.Width := Image1.Width - cOffset;
Image1.Height := Image1.Height - cOffset;
Exit;
end;
end;procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
FMouseDown := Button = mbLeft;
FOldPoint := Point(X, Y);
end;procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
FMouseDown := False;
end;procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if not FMouseDown then Exit;
if not RadioButton1.Checked then Exit;
Image1.Left := Image1.Left + (X - FOldPoint.X);
Image1.Top := Image1.Top + (Y - FOldPoint.Y);
end;procedure TForm1.RadioButton1Click(Sender: TObject);
begin
Image1.Cursor := crHandPoint;
end;procedure TForm1.RadioButton2Click(Sender: TObject);
begin
Image1.Cursor := crCross;
end;procedure TForm1.RadioButton3Click(Sender: TObject);
begin
Image1.Cursor := crUpArrow;
end;end.
老师,你怎么把窗体文件也贴出来了!
楼主,我老师的回答是正确的,我试过啦!
:)
(回答问题的过程: zswang(伴水) 老师写代码,FlyingQQ(FlyingQQ)测试)
嘻嘻嘻嘻嘻嘻嘻嘻嘻
嘻嘻嘻通过!嘻嘻嘻
嘻嘻嘻嘻嘻嘻嘻嘻嘻
Image1.AutoSize := False;
这两句有什么作用?
Image1.AutoSize := True; //让图片控件和图片区域保持一样的大小
Image1.AutoSize := False; //恢复以前的状态,否则怎么改变它的大小?