cancel
Showing results for 
Search instead for 
Did you mean: 

Show context menu when clicking on a Button

Former Member
0 Kudos

Hi, is it possible to show an own context menu (like the right-click-menu) after clicking on a button in a Form?

Regards Philipp

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member445524
Participant
0 Kudos

Hmmmm. What about the following:

1) Write your own 'generic' form to represent a set of commands (in a matrix, for example).

2) Create a wrapper class for this form that will be able to show this form with a specified set of actions and handle events of the form.

3) Every time the button is pressed:

a) Disable event handling of the main form (because the context menu must be 'modal' in respect to the form from which it has been invoked)

b) Use the above class to Show the menu and handle the user choice.

Of course, this class should treat event-handling code in a generic way. Using delegates, for example, so you can write custom handlers for every option in your context menu and initialize with them every instance of your class. Such handlers might accept the main form and the user choice as parameters.

Anton

Former Member
0 Kudos

Well, thanks. but there hast to be an other (easier) way do do it, or?

Former Member
0 Kudos

I thought about firing the event when i handle the click event.

if (pVal.ItemUID == "cmdButton" && pVal.EventType == SAPbouiCOM.BoEventTypes.et_CLICK)
            {
                if ((pVal.BeforeAction == true))
                {
                    oForm = SBO_Application.Forms.GetFormByTypeAndCount(pVal.FormType, pVal.FormTypeCount);
                    
                    try{
                        SAPbouiCOM.ContextMenuInfo cn = new SAPbouiCOM.ContextMenuInfo();
                        Test(ref cn, out BubbleEvent);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }

but then i have the problem with the ContextMenuInfo object. how can i generate that? the line with the new contextmenuinfo generates an error!

former_member445524
Participant
0 Kudos

Yes, this solution is quite laborous to implement, but then you'll have a generic, reusable class... Write once, use everywhere.

but then i have the problem with the ContextMenuInfo object. how can i generate that? the line with the new contextmenuinfo generates an error!

I don't know. Some objects just won't work this way, 'cause such usage is not intended. It sounds like hacking, interfering with the event-handling mechanism by "faking" events. I think UI Api has been protected from such 'unsafe' usage.

Anton