Autor Beitrag
ak
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 240

Suse Windows 9 XP
D6 Professional
BeitragVerfasst: Do 15.01.04 23:20 
Hallo Leute,

ich habe ein Image in dem auf Knopfdruck eine Linie gezeichnet wird:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
procedure TForm1.Button2Click(Sender: TObject);
begin
  image1.Canvas.Pen.Width:=2;
  image1.Canvas.Pen.Color:=clred;
  image1.Canvas.LineTo(10,10);
  image1.Canvas.LineTo(90,10);
  image1.Canvas.LineTo(90,90);
  image1.Canvas.LineTo(100,90);
  image1.Canvas.LineTo(100,10);
  image1.Canvas.LineTo(110,10);
  image1.Canvas.LineTo(110,90);
  image1.Canvas.LineTo(120,90);
  image1.Canvas.LineTo(120,10);
  image1.Canvas.LineTo(130,10);
  
end;


Jetzt möchte ich, wenn der Benutzer mit dem Mauszeiger auf Koordinate (100,90) geht einen Klartext ausgeben, bei Koordinate (130,10) wiederum einen andern Klartext. Geht so etwas bei Bildern?

_________________
Gruß AK
ak Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 240

Suse Windows 9 XP
D6 Professional
BeitragVerfasst: Fr 16.01.04 08:03 
Der Klartext der als Hint oder in einem Textfeld erscheinen soll, kann auch auf Mausklick erstellt werden.

Gruß

_________________
Gruß AK
Simon Joker
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 236
Erhaltene Danke: 1



BeitragVerfasst: Fr 16.01.04 09:22 
Hi Ak

Sicher geht das. Nutz dafür doch einfach das OnMouseMove-Event.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
procedure TFormMain.ImgMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  //Initialisierung
  Klartext := '';

  //Koordinate1
  if (x = 100) and (Y = 90) then
    Klartext := 'Kordinate 1';
  //Koordinate2
  if (x = 130) and (Y = 10) then
    Klartext := 'Kordinate 2';
  //usw.

end;


So siehts aus für fixe Punkte. Natürlich kannst oder besser solltest du die Punkte in ein Array packen und das dann mit einer Schleife durchsuchen. Auch solltest du den Bereich für Treffer um +/- 1 Pixel erweitern. Sonnst bekommt man denn Punkt schwer zusfassen.

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:
var 
  PointList : array of TPoint; //Dynamisches Array

...
//Array füllen
  SetLength(PointList,10);
  PointList[0].X := 10;  PointList[0].Y := 10;
  PointList[1].X := 90;  PointList[1].Y := 10;
  ...
  PointList[8].X := 120;  PointList[8].Y := 10;
  PointList[9].X := 130;  PointList[9].Y := 10;
...

procedure TForm1.DrawPointList;
var 
  i : integer;
begin  
  if length(PointList) >= 2 then 
    begin //prüfen ob es überhaut lohn zu zeichnen; mindestens 2 Punkte
      image1.Canvas.Pen.Width:=2; 
      image1.Canvas.Pen.Color:=clred;
      //Bewegen zum ersten Punkt
      image1.Canvas.MoveTo(PointList[0].X,PointList[0].Y);
      for i := 1 to high(PointList) do //Linie zu allen folgenden Punkten
        image1.Canvas.LineTo(PointList[i].X,PointList[i].Y);
    end;    
end;

procedure TFormMain.ImgMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var 
  i : integer;
begin
  //Initialisierung
  Klartext := '';
  //Suche ersten Punkt mit den Koordinaten x/y +-1
  for i := 0 to high(PointList) do
    if (Y >= PointList[i].X-1) and (Y <= PointList[i].X+1) and 
       (Y >= PointList[i].Y-1) and (Y <= PointList[i].Y+1) then
      begin 
        Klartext := 'Kordinate ' + IntToStr(i);
        break; 
      end;
end;


Der Code ist ungetestet!
ak Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 240

Suse Windows 9 XP
D6 Professional
BeitragVerfasst: Fr 16.01.04 19:36 
Danke für den Tip, ich probiere es gleich mal aus.

_________________
Gruß AK