How to have a list of options when clicking a TButton on Firemonkey? - delphi

I know that TButton on firemonkey let me add a TPopUp Menu. But it only works when you right click it.
I need make it open right below the button when you do the normal click.
PopupMenu.PopUp(X, Y) is based on the form I believe. How to translate the X,Y of the button (that is deep inside other layouts) to the same coordinate?
And when clicking and the PopUp is shown some weird behavior happens with the selection bar of the popup menu that disappear. The button keeps pressed, that is good.

Look here:
http://blogs.embarcadero.com/sarinadupont/2013/10/17/463/
Is an example for mobile, but you use in desktop too.

Related

How to close a TMultiview from code in Delphi XE8?

I have a form with a speedbutton linked to a TMultiView component.
On the multiview I have some buttons. When clicking on any of the buttons I want the multiview to close and depending on the clicked button, different functions to be called. I have tried to set the Visible property of my MultiView to false, but the shadow over the form then remains. If I click on the speedbutton again, then menu disappears, and also the shadow, as expected.
Is there a way to solve this?
I'm using Deplhi XE 8.1
Multiview.HideMaster will close the multi view. Call this whenever/wherever you want the multiview to close.

Is it possible to open a menu when a button is clicked in Rad Studio

It is possible to do in most other environments, but i'm unable to find a way to do this with Embarcadero.
The closest thing that was found is setting the DropDownMenu property on a button with bsSplitButton property... however this has a problem that it only works with Vista (so in fact i cannot even test if it works at all).
Alternatively it is currently possible to add a regular right button drop down.
Is there a way to connect button's left button click event to a specific drop down menu?
Your button's OnClick event handler can call the Popup() method of a TPopupMenu component. You do not have to assign the PopupMenu to the button unless you want it to handle right-clicking.

Avoid click propagation on Page that is under the current page on a TPageControl

I have a TPageControl that contains five pages and the page shown is alternated setting the ActivePageIndex property in this way:
PageControl1.ActivePageIndex := 4;
the problem is that the page below covered by the page currently shown get click on his buttons while the mouse is pressed on the above page, how can I avoid this behaviour ? How can I avoid the propagation of the click on Pages below the currently shown (that is also the current index)?
The application uses CLX as Graphics library instead of VCL.
Delphi does not do click Propagation.
I would check if the button that gets click are placed on the TabSheet and not on the parent control. Find the button you want in the drop down list of object inspector and press - the selected item will be the parent of the button. Is it a TabSheet?
Or you can add this code as a first line of your button-click-function
ShowMessage(TButton(Sender).Parent.Name);

Why doesn't clicking on my TToolButton show the DropdownMenu?

I'm using Delphi 2010 and I have a TToolButton contained by a TToolBar. Assigned to the 'DropdownMenu' property of my TToolButton is a standard TPopupMenu.
The only way I can get the menu to appear is to click on the area pointed to by the red arrow in the image. Currently, clicking the area pointed to by the green arrow shows the button as pressed, but the dropdown menu does not appear.
What I want is if the user clicks anywhere (pointed to by green arrow or red arrow) for the menu to appear. Is it possible to enable this functionality?
The idea of the tbsDropDown style is to have a button that triggers some default action when clicked, but provides more variations of that action in the drop down menu.
If you don't care about the down arrow disappearing, you can set the style to tbsButton and no matter where the button is clicked, it will show the popup menu.
If you are like me and you do want to have the arrow there to indicate that there are more options behind this button, you can call CheckMenuDropdown in the button's OnClicked event handler.
Set Style to tbsButton. Then you can click anywhere to show the drop-down menu, but you will lose the arrow.

Mimic outside click on a popup menu

You know how in a popup menu if you click outside of the menu the popup disappears? Well I would like to reproduce that.
Currently I am having a panel created with some components on it when a button is clicked. The panel and sub components go away when you click a certain button on the panel. However I want it to go away if you click anywhere outside of the panel.
I think you would need to install and application-wide mouse message hook, and if your panel is visible and the coordinates of the mouse event are outside of your panel bounds, then hide the panel. Also handle the WM_ACTIVATE message in your form.
[Edited: removed answer involving SetCaptureControl() because the bahaviour is not appropriate in this circumstance]

Resources