How to...BevelButton with menu

I have been trying to implement a bevel button with a popup menu in a way that I think should be possible but I haven’t had any success yet. I haven’t found any example code or anything on the forum that covers what I want yet.

What I am trying to do:

Standard click on button - carry out an action with a default setting
Click on button disclosure triangle or right-click - menu pops up and if item selected then carry out action with selection

What is happening:

All clicks anywhere on the button displays the popup menu and action is carried out with selection

I have tried creating the popup menu in the Open event and the ConstructContextualMenu event. And I have tried different combinations of handling actions with the Action event and the ContextualMenuAction event.

What am I missing?

Thanks,
Peter

[quote=128921:@Peter Mitchell]I have been trying to implement a bevel button with a popup menu in a way that I think should be possible but I haven’t had any success yet. I haven’t found any example code or anything on the forum that covers what I want yet.

What I am trying to do:

Standard click on button - carry out an action with a default setting
Click on button disclosure triangle or right-click - menu pops up and if item selected then carry out action with selection

What is happening:

All clicks anywhere on the button displays the popup menu and action is carried out with selection

I have tried creating the popup menu in the Open event and the ConstructContextualMenu event. And I have tried different combinations of handling actions with the Action event and the ContextualMenuAction event.

What am I missing?

Thanks,
Peter[/quote]

Are you not confusing PopupMenu and ContextualMenu ?

Can you post what you have so far ?

I have been adding and removing code so don’t really have a lot I can post.

I have set the property ‘HasMenu’ to ‘Normal Menu’ for the bevel button. This causes the the button to have a small disclosure triangle in the button. Adding a menu in the Open event like this:

Me.AddRow(“Last Day”)
Me.AddRow(“Last 2 Days”)
Me.AddRow(“Last Week”)

When the button is clicked the popup menu is displayed. But I would like it to display the popup menu only if I click on the disclosure triangle area of the button. A click anywhere else I want to just carry out a default action without the popup menu being displayed.

I have done something like this under another development environment. But maybe this is not possible with Xojo?

Thanks,
Peter

Use the MouseDown event to chose between disclosure triangle/menu and rest of the button/click :

Function MouseDown(X As Integer, Y As Integer) As Boolean if x > me.width-11 and x<me.width-7 then //Display menu else //This is click msgbox str(x)+" "+str(y) return true end if End Function

You put what you would in the Action event where I commented “This is click”. In this example, I just displayed a msgbox with x and y. The rest of the menu appears when one clicks on the disclosure triangles. You can play on the values of X to make that area larger, for instance to drop the menu on the whole right side starting at the disclosure triangle. The values I used are for Mac OS X. They may be different for Windows or Linux.

Thanks for the suggestion. I had been trying to use the MouseUp event to do the same thing but was not having any luck. Don’t know why the MouseUp was never firing. (I was returning true in the MouseDown event.)

Anyway, I’ll have to decide whether to live with it the way it is or implement in the MouseDown event. The drawback to the MouseDown is that you can’t change your mind and move off the button before releasing the mouse in order for nothing to be done.

[quote=128932:@Peter Mitchell]Thanks for the suggestion. I had been trying to use the MouseUp event to do the same thing but was not having any luck. Don’t know why the MouseUp was never firing. (I was returning true in the MouseDown event.)

Anyway, I’ll have to decide whether to live with it the way it is or implement in the MouseDown event. The drawback to the MouseDown is that you can’t change your mind and move off the button before releasing the mouse in order for nothing to be done.[/quote]

OK. If you want to still have the “regret” option, just stick a Button on top of the PopupMenu, and just make sure to leave the right hand side with the arrows free so the user can obtain the drop down menu. You will be able to use the Action event of the button, and when the user clicks on the right hand side, he will get the menu.

I tried with both a regular button and a BevelButton, the latter may somehow look more natural. You just need to make it 21 pixels high.