MiniMenu.dll, a context menu for the device.

taximania

Well-Known Member
Licensed User
Longtime User
I know that FormLib.dll has a contextmenu in it,
But this is short and neat and may be of interest to someone.

mini.New1("?")
'?' is any object in your app. Form1, Label1, Textbox1 etc.

The contextmenu has 3 items in it.
The default text for the items can be read or changed by
the relevant mini.Item'x'text method.

sub mini_PopUp is fired before the menu is displayed,
but after the menu has been initiated, 'right click or
stylus touch on the 'control' defined in the New1("?")

Hence the use of the timer1 in the Sub mini_PopUp

If a menu item is not clicked,
mini.RespText returns the string "null"
mini.RespValue returns the int 0

If the menu is clicked,
mini.RespText returns the 'preset' or 'set' text for the Item
mini.RespValue returns the 'preset' Int for item, 1 - 3.



B4X:
Sub Globals
   'Declare the global variables here.
End Sub

Sub App_Start
   Form1.Show
   mini.New1("Form1")
End Sub

Sub mini_PopUp
timer1.Interval=2000
timer1.Enabled=True
End Sub

Sub Timer1_Tick
timer1.Enabled=False
Msgbox(mini.RespText,mini.RespValue)
End Sub

Ive added the .dll, .sbp source example and the Class1.cs C# file.

@whoever knows, how do I get the MenuItem.Click event to work :confused:
 

Attachments

  • miniMenu.zip
    2.8 KB · Views: 36
Last edited:

taximania

Well-Known Member
Licensed User
Longtime User
Timer gone, many thanks AGraham, :icon_clap: new working lib in 1st post.

'sub mini_Click' now returns the selected menu item.

Edit: As an afterthought, the mini_Popup event is still triggered before the menuitem
options are shown. I'll leave it there for now. You don't have to use it.
At least you have the option to know a menu item can be selected before it actually is ;-)

Now for the biggie >> ?? :sign0060: Watch this space :sign0082:
 
Last edited:

agraham

Expert
Licensed User
Longtime User
At least you have the option to know a menu item can be selected before it actually is .
It's better than that. In the Popup event you can change the menu item text, add new menu items etc. It is an opportunity to tailor the context menu to the present situation rather than having to do it pre-emptively in advance.
 

taximania

Well-Known Member
Licensed User
Longtime User
I've just realised the code you translated for me doesn't use the
Show(this, contextmenu bla bla bla) bit of code.
I'm sure it existed in my original code, what fires the menu to display ?

I haven't got a copy of my original code to look what I had wrote !
I overwrote? it with your working code :sign0148:
 

agraham

Expert
Licensed User
Longtime User
I'm sure it existed in my original code
You did have the following but I removed it as it did nothing because you hadn't added it to the Form MouseDown event and it's not needed anyway.
B4X:
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
    if (e.Button == MouseButtons.Right)
    {
        mnu.Show(frm, new Point(e.X, e.Y));
    }
}
what fires the menu to display?
The users' right click, you just get called along the way as long as you have added the events. Show lets you display a ContextMenu by other means, such as a button press, if you want to.
haven't got a copy of my original code to look what I had wrote !
I overwrote? it with your working code
Tut!
 
Top