Autor Beitrag
stigge
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 426

WinXP
Delphi 2007
BeitragVerfasst: Di 13.03.07 16:24 
Kann ich ein Popup-Menu erstellen, das angezeigt wird, wenn man mit der rechten Maustaste auf ein Listboxitem klickt? Also ein normales Popupmenu halt mit einer Listbox?
freak4fun
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 604
Erhaltene Danke: 4

Win 7 Pro
VS 2013 Express, Delphi, C#, PHP, Java
BeitragVerfasst: Di 13.03.07 16:32 
Ja, PopUp auf Form ziehen und der ListBox zuweisen. ;)

MfG
freak

_________________
"Ich werde auf GAR KEINEN Fall…!" - "Keks?" - "Okay, ich tu's."
i++; // zaehler i um 1 erhoehen
stigge Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 426

WinXP
Delphi 2007
BeitragVerfasst: Di 13.03.07 16:44 
Ähm ja natürlich^^ Hatte gerade nen Blackout (mal wieder) :wink:
stigge Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 426

WinXP
Delphi 2007
BeitragVerfasst: Di 13.03.07 17:34 
Und wenn ich jetzt den Itemindex des Listeneintrags haben will, auf dem man das Popupmenu aufgerufen hat?
Saubäär
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 376



BeitragVerfasst: Di 13.03.07 17:50 
Moin,

so geht es (wenn ich dich nicht falsch verstanden habe :? ):

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure TForm1.ListBox1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
 if not (Button = mbRight) then
  Exit;
 (FindComponent('PopupMenu' + ListBox1.Items[ListBox1.ItemIndex]) as TPopupMenu).Popup(Mouse.CursorPos.X, Mouse.CursorPos.Y);
end;


allerdings musst du die Namen der PopupMenüs anpassen (z.B.):

ausblenden Quelltext
1:
2:
3:
4:
Listbox:
--------
Name     => PopupMenuName
Alter    => PopupMenuAlter

Gruß

Saubäär
stigge Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 426

WinXP
Delphi 2007
BeitragVerfasst: Mi 14.03.07 19:41 
Funktioniert noch nicht so richtig:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
procedure TForm1.AusListeentfernen1Click(Sender: TObject);
begin
ListBox3.Items.Delete(listbox3.itemindex);
end;

procedure TForm1.ListBox3MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
if not (Button = mbRight) then
  Exit;
 (FindComponent('PopupMenu' + ListBox3.Items[ListBox3.ItemIndex]) as TPopupMenu).Popup(Mouse.CursorPos.X, Mouse.CursorPos.Y);
end;

Also ausListeentfernen ist ein Element des Popup-Menüs. Wenn ich aber auf ein Element rectsklicke, bekomme ich eine Fehlermeldung:
"Listenindex überschreitet das Maximum (-1)"
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Mi 14.03.07 20:09 
Hallo,

denke mal das Dir ListBox.ItemAtPosweiterhilft.

In PopupMenuPopup mit ItemAtPos das Item ermitteln, zwischenspeichern z.B. in PopupMenu.Tag und dann in deinem "AusListeentfernen1Click" auswerten.

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
stigge Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 426

WinXP
Delphi 2007
BeitragVerfasst: Mi 14.03.07 20:20 
OK, aber ich verstehe die Parameter noch nicht so ganz.
Was muss ich für Parameter verwenden?
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Mi 14.03.07 20:27 
Hallo,

ausblenden Delphi-Quelltext
1:
function ItemAtPos(Pos: TPoint; Existing: Boolean): Integer;					

Pos: TPoint = Mauskoordinaten, z.B. mit GetCursorPos ermitteln
Existing: Boolean = auf True setzen, dann wird -1 zurückgeliefert, wenn z.B. unterhalb der Items geklickt wird.

//Edit: In meiner Delphi-Hilfe ist auch ein Beispiel zu ItemAtPos

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
Saubäär
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 376



BeitragVerfasst: Mi 14.03.07 20:40 
user profile iconstigge hat folgendes geschrieben:

Also ausListeentfernen ist ein Element des Popup-Menüs. Wenn ich aber auf ein Element rectsklicke, bekomme ich eine Fehlermeldung:
"Listenindex überschreitet das Maximum (-1)"


Hi,

die Fehlermeldung kommt wenn das Popupmenu, dass du ansprichst nicht existiert. Wie gesagt:
ausblenden Quelltext
1:
2:
3:
4:
Listbox:
--------
Name     => PopupMenuName
Alter    => PopupMenuAlter


Dann müsste es ohne Probleme funktionieren.
stigge Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 426

WinXP
Delphi 2007
BeitragVerfasst: Mi 14.03.07 20:44 
Sorry aber ich blicks immer noch nicht :oops:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
var stell: integer;...

procedure TForm1.AusListeentfernen1Click(Sender: TObject);
begin
ListBox3.Items.Delete(stelle);
end;

procedure TForm1.ListBox3MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
if not (Button = mbRight) then
  Exit;
stelle := ListBox3.ItemAtPos(getcursorpos, true);
end;

Fehler:
[Fehler] Unit1.pas(1107): E2035 Nicht genügend wirkliche Parameter
stigge Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 426

WinXP
Delphi 2007
BeitragVerfasst: Mi 14.03.07 20:47 
Die Methode von Saubär auch nicht :oops: :oops: :oops:
Saubäär
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 376



BeitragVerfasst: Mi 14.03.07 20:51 
Hi stigge,

ich weiß leider immer noch nicht genau, was du überhaupt machen willst. Bei meiner Methode kannst du mit jedem Element der ListBox
ein! PopupMenu ansprechen, heißt: Des Item hat sein eigenes PopupMenu,
(dass vorher erstellt worden sein muss und: PopumenuItemName heißen muss).
stigge Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 426

WinXP
Delphi 2007
BeitragVerfasst: Mi 14.03.07 20:54 
user profile iconSaubäär hat folgendes geschrieben:
Hi stigge,

ich weiß leider immer noch nicht genau, was du überhaupt machen willst. Bei meiner Methode kannst du mit jedem Element der ListBox
ein! PopupMenu ansprechen, heißt: Des Item hat sein eigenes PopupMenu,
(dass vorher erstellt worden sein muss und: PopumenuItemName heißen muss).


Achso, nein! Ich wollte nur den Itemindex des Items, das mit der rechten Maustaste angeklickt wurde, herausfinden!!!
Das reicht mir schon, den Rest schaffe ich selber :wink: Oder besser gesagt, ich WILL
Saubäär
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 376



BeitragVerfasst: Mi 14.03.07 20:58 
Moin,

achso ok!

ausblenden Delphi-Quelltext
1:
2:
ListBox1.ItemIndex; << Index des selektierten Items
ListBox1.Items[ListBox1.ItemIndex]; << Name des selektierten Items

Gruß

Saubäär
stigge Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 426

WinXP
Delphi 2007
BeitragVerfasst: Mi 14.03.07 21:00 
user profile iconSaubäär hat folgendes geschrieben:
Moin,

achso ok!

ausblenden Delphi-Quelltext
1:
2:
ListBox1.ItemIndex; << Index des selektierten Items
ListBox1.Items[ListBox1.ItemIndex]; << Name des selektierten Items

Gruß

Saubäär

Jo, weiß ich schon länger^^ Das Problem ist das beim Rechtsklick das Item nicht anselektiert wird^^
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: Mi 14.03.07 21:02 
Hallo

itematpos war schon richtig, aber du mußt die x,y Koordinaten übergeben, die sich auf die Listbox beziehen und nicht getcursorpos

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
procedure TForm1.ListBox1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if button = mbright then
    showmessage(inttostr(ListBox1.ItemAtPos(point(x,y),true)));
end;

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
stigge Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 426

WinXP
Delphi 2007
BeitragVerfasst: Mi 14.03.07 21:06 
user profile iconKeldorn hat folgendes geschrieben:
Hallo

itematpos war schon richtig, aber du mußt die x,y Koordinaten übergeben, die sich auf die Listbox beziehen und nicht getcursorpos

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
procedure TForm1.ListBox1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if button = mbright then
    showmessage(inttostr(ListBox1.ItemAtPos(point(x,y),true)));
end;

Gut! Jetzt muss nur noch das Popup-Fenster erscheinen!
ausblenden Delphi-Quelltext
1:
stelle := ListBox3.ItemAtPos(point(x,y),true);					

Halt das Fenster soll da erscheinen, wo man einen Rechtsklick gemacht hat.
stigge Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 426

WinXP
Delphi 2007
BeitragVerfasst: Mi 14.03.07 21:09 
Hat sich geklärt:
ausblenden Delphi-Quelltext
1:
2:
stelle := ListBox3.ItemAtPos(point(x,y),true);
popupmenu1.Popup(Mouse.CursorPos.X, Mouse.CursorPos.Y);

Danke, aber ich hab noch eine Frage:
Kann man irgendwie ein spezielles Item in einer Listbox anselektieren?
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: Mi 14.03.07 21:10 
gugg dir popup an, autopoup muß auf false stehen, wenn du das popupmenu der listbox zugewiesen hast
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure TForm1.ListBox1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
Var Pt:tpoint;
begin
  if button = mbright then
    begin
      ListBox1.ItemIndex:=ListBox1.ItemAtPos(point(x,y),true);
      getcursorpos(PT);
      PopupMenu1.Popup(pt.X,pt.y);
    end;
end;

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)