Autor Beitrag
Pepp3r
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 82



BeitragVerfasst: Mi 15.11.06 21:36 
Folgendes:
Ich möchte auf image1 ein rectangle (quadrat) aufziehen können, das heißt auf mousedown werden die x1 und y1 coordinaten festgelegt und bei mouseup x2 und y2 festgelegt (in image1.canvas.rectangle(x1,y1,x2,y2)).
Als Resultat möchte ich also ein quadrat in beliebiger Größe auf aufziehen können. Wie ist sowas möglich????
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mi 15.11.06 21:39 
Moin!

Schau dir mal Image1.Canvas.DrawFocusRect() an, damit geht sowas. ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Pepp3r Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 82



BeitragVerfasst: Mi 15.11.06 21:43 
user profile iconNarses hat folgendes geschrieben:
Moin!

Schau dir mal Image1.Canvas.DrawFocusRect() an, damit geht sowas. ;)

cu
Narses


erstma danke für die schnelle antwort :)

also dieser befehl ist mir neu, was muss denn zwischen die klammern damit es funktioniert?
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mi 15.11.06 21:46 
Moin!

Stell mal den Cursor auf die Methode und drück F1. :D

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Pepp3r Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 82



BeitragVerfasst: Mi 15.11.06 22:17 
sry, aber das hilft mir net weiter, bin in sachen delphi eher noch in den windeln.....

aaaalsoo, mir wird etwas von "(const Rect: TRect)" gesagt, vomitich ehrlich gesagt nicht recht hin weis.
Ich habe das so interpretiert, dass Rect eine Konstante von TRect ist. Wie es genau weiter geht, konnte mir weder das delphi-forum noch google sagen, was bedeudet, dass ich weiterhin auf euch angewiesen bin, so leit es mir auch tut :(
aim65
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 312

Win 9x, Win XP
Delphi 3pro, 7PE
BeitragVerfasst: Mi 15.11.06 22:59 
Vielleicht löst das dein Problem:
www.delphi-forum.de/...60378&highlight=
Pepp3r Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 82



BeitragVerfasst: Do 16.11.06 00:30 
danke aim, das thema hat mich ein stück weiter gebracht.
ich habe das was da stand ma 1:1 übernommen, aber als resultat hab ich dann keine quadrate, sondern komische striche die vertikal durchs bild laufen.
ich glaube, es könnte daran liegen, dass ich x1,x2,y1,x2 falsch definiert habe
ausblenden Quelltext
1:
var x1,x2,y1,x2:integer;					

da integer ja nur ganze zahlen beinhaltet, aber wie sollte ich das sonst definieren?
ansonsten hab ich keine ahnung wo der fehler liegen könnte :(
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 16.11.06 00:41 
Moin!

Hm, möchtest du sowas gummibandartiges haben, also sehen, wie das Rechteck aufgezogen wird, oder willst du einfach nur mit der Maus ein Rechteck "zeichnen"? :gruebel:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Pepp3r Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 82



BeitragVerfasst: Do 16.11.06 00:55 
ich möchte wie ein "gummiband" ein quadrat aufziehen können :)
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 16.11.06 01:05 
Moin!

Dann probier das mal so: ;)
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:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure DrawFocusRect;
    procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  private
    { Private-Deklarationen }
  public
    X0,Y0,MX,MY: Integer;
    InMove: Boolean;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  InMove := FALSE;
end;

procedure TForm1.DrawFocusRect;
begin
  Form1.Canvas.DrawFocusRect(Rect(X0,Y0,MX,MY));
end;

procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if (Button = mbLeft) then begin
    X0 := X;
    MX := X;
    Y0 := Y;
    MY := Y;
    DrawFocusRect;
    InMove := TRUE;
  end;
end;

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  if (InMove) then begin
    DrawFocusRect;
    MX := X;
    MY := Y;
    DrawFocusRect;
  end;
end;

procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if (InMove) then begin // unerwünschte Klicks filtern
    DrawFocusRect;
    MX := X;
    MY := Y;
    InMove := FALSE;
  end;
end;

end.

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Pepp3r Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 82



BeitragVerfasst: Do 16.11.06 13:16 
also das klapt schonma im sinne des gummibandes, aber ich hab dich falsch verstanden, ich möchte doch ein rechteck "zeichnen" ~~ oh man, sry, jetz hab ich erst richtig verstanden wie du das meintest.
Blackheart666
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: Do 16.11.06 14:03 
user profile iconPepp3r hat folgendes geschrieben:
danke aim, das thema hat mich ein stück weiter gebracht.
ich habe das was da stand ma 1:1 übernommen, aber als resultat hab ich dann keine quadrate, sondern komische striche die vertikal durchs bild laufen.
ich glaube, es könnte daran liegen, dass ich x1,x2,y1,x2 falsch definiert habe
ausblenden Quelltext
1:
var x1,x2,y1,x2:integer;					

da integer ja nur ganze zahlen beinhaltet, aber wie sollte ich das sonst definieren?
ansonsten hab ich keine ahnung wo der fehler liegen könnte :(


ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
var
  Form1: TForm1;
  x1,x2,y1,x2:integer;
implementation

{$R *.dfm}

Blackheart666

_________________
Blackheart666
Der Irrsinn ist bei Einzelnen etwas Seltenes, - aber bei Gruppen, Parteien, Völkern, Zeiten die Regel. (Friedrich Nietzsche)
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 16.11.06 14:48 
Moin!

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;  
  Shift: TShiftState; X, Y: Integer);  
begin  
  if (InMove) then begin // unerwünschte Klicks filtern  
    DrawFocusRect;  
    MX := X;  
    MY := Y;  
    InMove := FALSE;
    Form1.Canvas.Rectangle(X0,Y0,MX,MY);  
  end;  
end;

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
aim65
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 312

Win 9x, Win XP
Delphi 3pro, 7PE
BeitragVerfasst: Do 16.11.06 15:46 
Hab erst jetzt mal wieder reingeguckt. Die Variablendeklaration x1,y1,x2,y2:Integer hatte ich in meinem Beispiel vorausgesetzt. Wenn Du das wie von Blackheart66 einsetzt, geht's auf jeden Fall.
Alle Beispiele hier beziehen sich auf die Form als Canvas. Falls Du das in einem Image machen willst, mußt du eben den Canvas darauf beziehen und natürlich auch die Mouse-Events vom Image verwenden (denke ich mir so... nicht probiert).

Übreigens: wenn Du das Quadrat mit der Maus in y-Richtung aufziehen willst, schreibst Du das hier
ausblenden Delphi-Quelltext
1:
2:
 //x2 := x; y2 := y1+x-x1;    //Quadrat durch X-Verschiebung der Maus
  x2 := x1+y-y1; y2 := y;    //Quadrat durch y-Verschiebung

@ Narses: Deinen Ansatz muß ich mal ausprobieren.
aim65
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 312

Win 9x, Win XP
Delphi 3pro, 7PE
BeitragVerfasst: Do 16.11.06 16:10 
Hatte ich doch glatt übersehen...
Du hattest x1,x2,y1,x2 statt y2geschrieben. Das wollte Blackheart wohl ohne Kommentar andeuten.
Kein Wunder, daß Du da nur Linien kriegst. :D
Pepp3r Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 82



BeitragVerfasst: So 19.11.06 13:12 
ok leute, danke für die hilfe, ihr habt mich sehr weiter gebracht, das Problem is gelöst :>
Gruß
Pepp3r