![]() |
Re: problem mit "menüanzeige"
hi fiasko
danke für deine erklärung soweit komm ich da ja mit , aber ich weiss net wie ich das ganze "auf papier" bringe :( bin in delphi noch nicht soooo fit :/ wäre aber sehr freundlich von dir wenn du den code nachträglich noch posten könntest thx im vorraus mfg stoni |
Re: problem mit "menüanzeige"
Zitat:
Wenn du den Sourcecode anschaust, dann siehst du, dass die linke untere Ecke von SpeedButton1 als Ausgangspunkt dient:
Delphi-Quellcode:
Dies lässt sich verbessern, in dem man nicht SpeedButton1, sondern das übergebene Steuerelement als Ursprung nimmt:
procedure TForm1.SpeedButton1Click(Sender: TObject);
var pt: TPoint; begin pt.x := SpeedButton1.BoundsRect.Left; pt.y := SpeedButton1.BoundsRect.Bottom; pt := ClientToScreen(pt); PopupMenu1.Popup(pt.x, pt.y); end;
Delphi-Quellcode:
Man kann das PopupMenue natürlich auch so positionieren:
procedure TForm1.SpeedButton1Click(Sender: TObject);
var pt: TPoint; c : TControl; begin c := (Sender as TControl); pt.x := c.BoundsRect.Left; pt.y := c.BoundsRect.Bottom; pt := ClientToScreen(pt); PopupMenu1.Popup(pt.x, pt.y); end;
Delphi-Quellcode:
procedure TForm1.SpeedButton1Click(Sender: TObject);
var pt: TPoint; c : TControl; begin c := (Sender as TControl); // genau die Mitte des Controls berechnen pt.x := (c.BoundsRect.Right+c.BoundsRect.Left) div 2; pt.y := (c.BoundsRect.Top+c.BoundsRect.Bottom) div 2; pt := ClientToScreen(pt); PopupMenu1.Popup(pt.x, pt.y); end; |
Re: problem mit "menüanzeige"
hi shmia
vielen dank für deine hilfe aber so ganz funzt das noch immern icht :8 ich hab echt die vermututng dass es noch an dem panel liegt auf dem die buttons sind wie kann ich das mit reinbringen ? |
Re: problem mit "menüanzeige"
Hi,
ich glaub es kann nur daran liegen, dass du das Menu öffnen willst beim drücken der linken Maustaste, denn beim drücken der rechten Maustaste öffnet sich das PopupMenu genau neben dem Speedbutton. |
Re: problem mit "menüanzeige"
hab ez noch folgendes im netz gefunden :
Delphi-Quellcode:
Okay, this one is really beginning to bug me. Especially as it
should be really simple. I have a button that is within a panel on a form. This form is itself then embedded within the main form of the project at run time. When this button is clicked I need to display a popup menu aligned just beneath the button. No problem, I've done this hundreds of times before using code similar to the following: var APoint: TPoint; APoint.X := Button.Left; APoint.Y := Button.Top + Button.Height; APoint := Panel.ClientToScreen(APoint); PopupMenu.Popup(APoint.X, APoint.Y); Except that the fact the form is embedded seems to be messing up the ClientToScreen call and consequently the popup menu is not appearing nicely under the button (it has the right Top value, but the wrong Left value). I know I'm missing something simple here and I guess that is what is bugging me about it.
Delphi-Quellcode:
Don't worry guys, I've figured it out. Turns out that the
popup menu was wider than the button and given that the button was sitting by the right edge of the panel/screen, Windows was automatically adjusting the left position so that the entire menu would appear on screen. Of course, I'd forgotton that Windows does this. Knew it had to be something simple :) was soll ich damit anfangen ? *wargh* plz help me :( |
Re: problem mit "menüanzeige"
huhu ?!
weiss keiner rat?? :pale: |
Re: problem mit "menüanzeige"
Hallo,
huch, die Vorlesung hat ein bißchen länger gedauert :cyclops: Hier mal ein bißchen Code:
Delphi-Quellcode:
der Code übersetzt für jedes Parent Control die Coordinaten, außer für das Form selber. Das funktioniert so leider nicht mit den TButton, weil die nicht von TGraphicControl sondern TButtonControl abgelitten sind und es keine Superklasse gibt die das ClientToScreen kann. Also einfach ein Copy-n-Paste und das Graphic durch Button, dann klappt das eigentlich auch für die anderen Typen. Die Methode muß z.Zt. noch im TForm Objekt welches die ganzen Controls enthält ausgeführt werden, damit der Test "(o <> Self)" funzt, wenn man das noch bißchen anders schreibt z.B. mit Assigned(o.Parent) und boolische Ausdrücke nicht vollständig ausgewertet werden könnte man das auch in ne extra Unit packen.
procedure TForm1.SpeedButton1Click(Sender: TObject);
var o: TWinControl; pt: TPoint; begin if (Sender is TGraphicControl) then begin pt.x := TGraphicControl(Sender).Left + (TGraphicControl(Sender).Width div 2); pt.y := TGraphicControl(Sender).Top + (TGraphicControl(Sender).Height div 2); o := TGraphicControl(Sender).Parent; while Assigned(o) and (o <> Self) do begin pt := o.ClientToScreen(pt); o := o.Parent; end; PopupMenu1.Popup(pt.x, pt.y); end; end; |
Re: problem mit "menüanzeige"
fiasko...du bist genial :P :cheers:
es klappt - einwandfrei :hello: endlich - superklasse :roteyes: :spin2: :bounce2: :bouncing4: :bounce1: :dancer2: :dancer: :witch: muchas gracias :D |
Alle Zeitangaben in WEZ +1. Es ist jetzt 17:08 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz