Context Menu

Aspire89

Member
Licensed User
Hello.
Can I call a context menu when you click the left mouse button?
Thank you.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
It is possible with the help of the door library to show the context menu from code.
B4X:
Sub Globals

End Sub


Sub App_Start
      Form1.Show
      'Context menu
      Context1.New1
      Context1.AddItem("Yes")
      Context1.AddItem("No")
      Context1.AddItem("-") 
      Context1.AddItem("Maybe")
      
      'Objects required for the door library
      Obj1.New1(False)
      Obj1.Value = Context1.Value
      Obj2.New1(False)
      OA1.New1(2)
      Obj3.New1(False)
End Sub
Sub Form1_MouseDown(x, y)
    ShowContextMenu("Form1", x, y)
End Sub


Sub ShowContextMenu(ControlName, X, Y)
    OA1.SetValue(0, X, "System.Int32")
    OA1.SetValue(1, Y, "System.Int32")
    Obj2.CreateNew2("System.Drawing.Point" & Obj2.System_Drawing, OA1.Value)
    Obj3.FromControl(ControlName)
    OA1.SetObject(0, Obj3.Value)
    OA1.SetObject(1, Obj2.Value)
    Obj1.RunMethod4("Show", OA1.Value)
End Sub

Sub Context1_Click
    Form1.Text = Context1.Selectedtext
    Select Context1.SelectedText
        Case "Yes"
            'Do something
        Case "No"
            'Do something
        Case "Maybe"
               'Do something
      End Select
End Sub
 

Attachments

  • 1.sbp
    1.6 KB · Views: 194
Hello.
I have been trying to comprehend the Door libriry(so far in vain:)) and I tested this exampe and the one from the help file on my device.Neither of them works.:sign0137: I get error messages....
Could it be a problem with my device?
 

mjcoon

Well-Known Member
Licensed User
I've not used it but according to the DLL list there is:

HelpDevice 1.0 - Form help and context menu help for controls in device applications.

Maybe because you mentioned "left mouse button" you were assumed to be interested only in desktop, but then you say "Could it be a problem with my device?"...

HTH, Mike.
 
Hello Mike.
I didn't mention "left mouse button" it was aspire89 who did :)

My device types obj2.SystemDrawing instead of obj2.System_Drawing
and the app errors on this line.
If if i type with underscore obj2.System_Drawing I get an error anyways.
In the changeForm'sIcon example I encountered a similar problem.
Is there a workaround other than hitting my device against the wall and buying a new one?:)
Thank you.
 

corwin42

Expert
Licensed User
Longtime User
...
Neither of them works.:sign0137: I get error messages....

...
and the app errors on this line.
If if i type with underscore obj2.System_Drawing I get an error anyways.
In the changeForm'sIcon example I encountered a similar problem.
Is there a workaround other than hitting my device against the wall and buying a new one?

The first step towards a workaround would be to tell us what error you get and on which device.

If you don't tell us the exact error it is impossible to guess a solution!
 
Cheers for your input Markus.
My device is Rover,it's cheap and it has caused me a lot of problems not related to Basic4ppc.

obj2.SystemDrawing....error message is "Invalid property"
obj2.System_Drawing......errors on
obj1.RunMethod4("Show",OA1.Value) "NullReferenceExeption"
Both errors occur when the form is clicked.:(
 

agraham

Expert
Licensed User
Longtime User
obj2.System_Drawing - is correct or it would error on this line.

obj1.RunMethod4("Show",OA1.Value) - the real error is here, either Obj1 or OA1 have not been assigned correctly. I would have to see your exact code to comment further. Does it run OK on your desktop?
 
Top