Autor Beitrag
hibbert
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1007

WinServer2003, Win XP, Linux
D6 Pers, D05
BeitragVerfasst: Di 18.11.03 16:15 
Hi,
wie kann ich ein Image mit der Mausverschieben? (nicht im Entwurfmodus, sondern in meinem erstellten Programm)

Dann möchte ich noch das Bild an eine bestimmte stelle setzten, und wenn es an einer bestimmten stelle ist, dann soll eine aktion ausgeführt werden.

thx hibbert

Moderiert von user profile iconTino: Titel geändert; Topic verschoben.

_________________
I kunnen väl svara endast ja eller nej
Om i viljen eller nej
Killmag10
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 297

Suse Linux / DOS / Windows All In One ;)
D4 / D2005
BeitragVerfasst: Di 18.11.03 17:19 
Titel: Re: image verschieben
hier mit einen label:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    l: TLabel;
    procedure lMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure lMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  private
  my,mx:integer;  { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.lMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
mx:=x;
my:=y;
end;

procedure TForm1.lMouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
l.Left:=l.Left+(x-mx);
l.Top:=l.Top+(y-my);
end;

end.

_________________
Mega-inkompetente Computer-ruinierende Organisation spioniert ohne funktionierende Technik
hibbert Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1007

WinServer2003, Win XP, Linux
D6 Pers, D05
BeitragVerfasst: Di 18.11.03 22:47 
mhh, die form wird zwar compeliert, doch ich kann das label nicht verschieben...

egal wo ich hinklicke...

MfG Hibbert

_________________
I kunnen väl svara endast ja eller nej
Om i viljen eller nej
Killmag10
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 297

Suse Linux / DOS / Windows All In One ;)
D4 / D2005
BeitragVerfasst: Di 18.11.03 22:56 
zeig mal deinen code (komplett) ! oder hast du meine koplett copiert ?

_________________
Mega-inkompetente Computer-ruinierende Organisation spioniert ohne funktionierende Technik
hibbert Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1007

WinServer2003, Win XP, Linux
D6 Pers, D05
BeitragVerfasst: Mi 19.11.03 10:56 
ich habe deinen Quellcode 1:1 übernommen.
Dann habe ich ein Label mit dem Namen "l" draufgesetzt. Dann habe ich die Caption geändert, damit das Label mehr Fläche hat.

hibbert

_________________
I kunnen väl svara endast ja eller nej
Om i viljen eller nej
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19312
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mi 19.11.03 12:13 
Titel: Da fehlt dann noch was!
Hallo!

Du musst auch die beiden Ereignisse mit der Komponente verknüpfen!!

Dazu gehst Du in den Objektinspektor und klickst doppelt auf onMouseDown und onMouseUp!

Damit wird dann allerdings nicht eine Verschiebung während des Ziehens sondern nur nach dem Loslassen realisiert!

Wenn das Image mit dem Mauszeiger direkt mitgehen soll, musst Du auf onMouseMove reagieren!
Dann musst Du dort dasselbe machen, wei im geposteten Quelltext bei onMouseUp!

Ciao,
S.J.
Killmag10
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 297

Suse Linux / DOS / Windows All In One ;)
D4 / D2005
BeitragVerfasst: Mi 19.11.03 14:05 
@jaenicke: das geht nicht so einfach du must auch überprüfen ob es auch wierklich gerade verschoben wird !

hier mit verschiebung:

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    l: TLabel;
    procedure lMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure lMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure lMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure FormCreate(Sender: TObject);
  private
  my,mx,m:integer;  { Private-Deklarationen }
  a:boolean;
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.lMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
mx:=x;
my:=y;
a:=true;
end;

procedure TForm1.lMouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
l.Left:=l.Left+(x-mx);
l.Top:=l.Top+(y-my);
a:=false;
end;

procedure TForm1.lMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
if a then begin
l.Left:=l.Left+(x-mx);
l.Top:=l.Top+(y-my);
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
a:=false;
end;

end.


und denk dran das du die ereignisse auch wierklich Verknüpfst !

_________________
Mega-inkompetente Computer-ruinierende Organisation spioniert ohne funktionierende Technik
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: Do 20.11.03 08:53 
Hallo!

Also bei mir funktioniert es. Hab den Code 1:1 übernommen. Das Label in L umbenannt und die 4 Ereignisse verknüpft.

Gruß
Tino
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19312
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Do 20.11.03 17:25 
Titel: Viel einfacher:
Hallo!

@Killmag10: Stimmt! Das hatte ich vergessen und weil ich es nicht ausprobiert habe auch nicht gemerkt! :oops:

Ansonsten gibt es auch eine viel einfachere Möglichkeit, die ich beim letzten Mal nicht gefunden hatte:
:idea:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
const sc_dragmove = $f012;
begin
  ReleaseCapture;
  TWinControl(Image1).perform(wm_syscommand,sc_dragmove, 0);
end;


Dieser Tip steht auf delphi-source.de und stammt von Assarbad!

So geht es doch etwas einfacher, als umständlich alle Ereignisse zu benutzen :D !

Ciao,
S.J.
hibbert Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1007

WinServer2003, Win XP, Linux
D6 Pers, D05
BeitragVerfasst: Do 20.11.03 18:12 
Danke, das mit dem label funzt jetzt 1a :wink:

aber das letzte beispiel (von jaenicke) funzt leider nicht :cry:

aber tortzdem thx

hibbert

_________________
I kunnen väl svara endast ja eller nej
Om i viljen eller nej
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19312
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Fr 21.11.03 14:36 
Titel: Komisch
Hallo!

Das ist seltsam, dass das Beispiel nicht funktioniert, denn ich habe das extra noch einmal ausprobiert :!: !

Bei mir funktioniert es!

Kannst Du mal schreiben, was nicht geht, oder was (nicht) passiert?

Das Problem mit der anderen Methode ist nämlich, dass bei mir manchmal die zu bewegende Komponente nicht exakt mit der Maus mitlief, z.B. wenn ich an den Fensterrand kam, daher hatte ich das anders gelöst (so wie gepostet)!

MfG,
S.J.
hibbert Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1007

WinServer2003, Win XP, Linux
D6 Pers, D05
BeitragVerfasst: Fr 21.11.03 15:38 
ich habe jetzt das beispiel vom label benutzt und habe das "l" durch "image1" erstezt und in die Passende Procedur gesetzt, sodass das jetzt auch funzt.

THX
hibbert

_________________
I kunnen väl svara endast ja eller nej
Om i viljen eller nej
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19312
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mi 26.11.03 11:38 
Titel: Noch einmal, diesmal getestet:
Hallo!

Also, ich habe den Code-Schnipsel jetzt in ein kleines Beispiel eingepackt.

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, OleCtrls;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    procedure Memo1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Memo1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
const sc_dragmove = $f012;
begin
  ReleaseCapture;
  TWinControl(Memo1).perform(wm_syscommand,sc_dragmove, 0);
end;

end.


Das hat bei mir richtig funktioniert!!
Und es funktioniert zuverlässig, da es die entsprechenden Systemmöglichkeiten benutzt. Außerdem finde ich das viel eleganter... :wink:

Grüße,
S.J.
Chatfix
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1583
Erhaltene Danke: 10

Win 10, Win 8, Win 7, Win Vista, Win XP
VB.net (VS 2015), MsSQL (T-SQL), HTML, CSS, PHP, MySQL
BeitragVerfasst: Mi 26.11.03 13:28 
Also das letzte Beispiel hat bei mir (D6 Enterp//Win 2k) prima geklapt...

_________________
Gehirn: ein Organ, mit dem wir denken, daß wir denken. - Ambrose Bierce
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: Mi 26.11.03 13:35 
Der Tipp vom SwissDelphiCenter funktioniert nur mit Objekten die von TWinControl abgeleitet sind...! TLabel und TImage stammen aber von der "Grafik-Seite" und sind von TGraphicControl abgeleitet, nicht von TWinControl (sie besitzen daher auch kein Handle).

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!