Autor Beitrag
bwolf
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 50



BeitragVerfasst: Mi 18.10.06 12:23 
Hi all,

ich glaube zwar das ähnliches schon öfters gefragt wurde, hab aber auch nach längerem suchen nix gefunden - deshalb traue ich mich nochmal zu fragen ;)

Also ich will einen Button (oder was für ein Object auch immer) per Drag and Drop verschieben.
Allerdings möchte ich, das der Button und seine Beschriftung dabei sichtbar bleiben, der Cursor sich also nicht in den Standardcursor ändert.

Kann mir einer dazu nen Lösungsansatz oder nen Link verraten ?

Danke schonmal,
gruß ben
bwolf Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 50



BeitragVerfasst: Do 19.10.06 13:18 
Jo,

also ich ein nettes Tutorial gefunden (www.blong.com/Confer...rop/4114.htm#VCLDLLs), wo das ganze erklärt wird.

Nun wollte ich mir die eine Komponente von dort abschreiben, hab allerdings 2 Probleme:

Hier der Source:
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:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
unit MyDragButton;

interface

uses
  SysUtils, Classes, Controls, StdCtrls, Graphics, Types, QControls;

type
  TMyDragButton = class(TButton)
  private
    FDragImages: TDragImageList;
  protected
    function GetDragImages: TDragImageList; override;
    procedure MouseDown(Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer); override;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    { Published declarations }
  end;

procedure Register;

implementation


constructor TMyDragButton.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  ControlStyle := ControlStyle + [csDisplayDragImage];
end;

destructor TMyDragButton.Destroy;
begin
  FDragImages.Free;
  inherited;
end;

function TMyDragButton.GetDragImages: TDragImageList;
var
  Bmp: TBitmap;
  BmpIdx: Integer;
  Pt: TPoint;
begin
  if not Assigned(FDragImages) then
    FDragImages := TDragImageList.Create(Self);
  Bmp := TBitmap.Create;
  try
    Bmp.Width := Width;
    Bmp.Height := Height;
    Bmp.Canvas.Lock;
    try
      PaintTo(Bmp.Canvas.Handle, 00);
    finally
      Bmp.Canvas.Unlock
    end;
    FDragImages.Width := Width;
    FDragImages.Height := Height;
    BmpIdx := FDragImages.AddMasked(Bmp, clBtnFace);
    //Where is mouse relative to control?
    GetCursorPos(Pt);
    Pt := ScreenToClient(Pt);
    //Specify drag image and hot spot
    FDragImages.SetDragImage(BmpIdx, Pt.X, Pt.Y);
    Result := FDragImages;
  finally
    Bmp.Free
  end
end;

procedure TDragButton.MouseDown(Button: TMouseButton; Shift: TShiftState;
  X, Y: Integer);
begin
  inherited;
  //Automatically start dragging on a Ctrl-click
  if ssCtrl in Shift then
    BeginDrag(True)
end;

procedure Register;
begin
  RegisterComponents('Samples', [TMyDragButton]);
end;

end.



Also 1.
ausblenden Delphi-Quelltext
1:
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;					



Hier meint er, das die Dekleration von der vorherigen Deklaration abweicht.
Verstehe ich nicht ganz, da die Procedur in der Doku genau so drinsteht...

Und 2.
ausblenden Delphi-Quelltext
1:
ontrolStyle := ControlStyle + [csDisplayDragImage];					



Meint er hier, 'incomatible types'.
Woran könnte das liegen ?
Danny W.
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 296

Windows XP, WIN 2000
Delphi 2005 PE
BeitragVerfasst: Mo 04.12.06 16:16 
1. Kopier nur den Inhalt der Prozedur in dein Mousedown...
2. Was könnte wohl falsch sein ;) Ich weiß zwar nicht was das für Typen sind, allerdings scheinen sie sich nicht zu mögen ^^

_________________
"Ich find den Fehler nicht. Der Artist wird immer als "Syntax Error" gezeigt :("
"Ach verdammt, der Artist heißt wirklich "Syntax Error" xD"