Page 1 of 1
Dropdown menus
Posted: Mon Dec 21, 2020 5:24 pm
by ymerejsasnak
Hello...
Is there a way to trigger default right-click menu behavior after you've taken control of a component with "Wants Mouse Notifications"?
Basically what I'm trying to do is add a left-click menu on part of my module without blocking the default right-click menu. Is this possible in any way?
JK
Re: Dropdown menus
Posted: Thu Dec 24, 2020 11:32 am
by honki-bobo
Hey Jeremy,
I guess what you are looking for is the " int ShowDropDownMenu(String[] options, int currentlySelectedIndex, VoltageComponent showMenuUnderThisObject)" method of the VoltageModule object.
Once you get the hang of it, it is actually quite convenient.
You'll need a String[] that holds the menu items, e.g.
Code: Select all
private String[] waveforms = {"sin", "tri", "sqr", "saw", "rmp"};
, an int to hold the selected index, e.g.
and a VoltageComponent you want to attach the menu to, e.g.
In the "Notify" method add the following to the Button_Changed case:
Code: Select all
if (component == menuButton) {
menuSelection = this.ShowDropDownMenu(waveforms, menuSelection, menuButton);
if (menuSelection == 0) {
//do something
} else {
// do something else
} // ... and so on
}
Hope this helps.
Have a merry Christmas and happy holidays!
Re: Dropdown menus
Posted: Thu Dec 24, 2020 2:30 pm
by ColinP
I think what JK is after is a means of calling up the default VM right-click menu rather than just a custom menu.
I have a similar problem with trying to create programmatically operable toggle buttons from normal buttons. My code works but it disables VM's right-click menu for some reason.
How some events are dispatched in VM is a bit of a mystery but it would be handy to be able to call up the right-click menu from our own code so that we can replicate "normal" behaviour.