Delphi-PRAXiS
Seite 2 von 2     12   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi problem mit "menüanzeige" (https://www.delphipraxis.net/33142-problem-mit-menueanzeige.html)

stonimahoni 2. Nov 2004 13:41

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

shmia 2. Nov 2004 13:42

Re: problem mit "menüanzeige"
 
Zitat:

Zitat von stonimahoni
also deine lösung scheint brauchbar zu sein, doch wie positionier ich das teil richtig ??

ich hab halt rechts die buttonleiste und dort soll eigentlich neben dem einen button den ich drücke das popupding aufgehen und nicht irgwendwo im formular :)

Du kannst die linke obere Ecke des Popupmenues festlegen.
Wenn du den Sourcecode anschaust, dann siehst du, dass die linke untere Ecke von SpeedButton1 als Ausgangspunkt dient:
Delphi-Quellcode:
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;
Dies lässt sich verbessern, in dem man nicht SpeedButton1, sondern das übergebene Steuerelement als Ursprung nimmt:
Delphi-Quellcode:
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;
Man kann das PopupMenue natürlich auch so positionieren:
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;

stonimahoni 2. Nov 2004 13:53

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 ?

pjuk 2. Nov 2004 13:57

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.

stonimahoni 2. Nov 2004 14:38

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 :(

stonimahoni 3. Nov 2004 07:41

Re: problem mit "menüanzeige"
 
huhu ?!

weiss keiner rat?? :pale:

fiasko 4. Nov 2004 15:23

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:
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;
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.

stonimahoni 5. Nov 2004 10:00

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 05:56 Uhr.
Seite 2 von 2     12   

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz