Welcome Guest Search | Active Topics | Sign In | Register

Add item to ContextMenu to run a sub() Options
penright
Posted: Wednesday, July 8, 2020 9:36:32 AM

Rank: Advanced Member
Groups: Member

Joined: 10/30/2017
Posts: 43
Not sure how to explain what I need so let me try and say how I was attempting to do it and then maybe someone can suggest the right way. :-)

I was wanting to add to the context menu a way of copying the URL to the clipboard. So now when I right-click the ContexMenu it is modified via the BeforeContextMenu(). Then inside of the sub that handles the _WebView.Command event, test on the command ID.
Looks like you can add CommandID, but not some sort of "address of" type function.
So it would work something like add menu item "Copy URL" that executed a sub CopyURL(), that executed Clipboard.SetText(my.url)
Does this mean I need to register a custom CommandID?


Code: Visual Basic.NET
Private Sub _WebView_BeforeContextMenu(sender As Object, e As BeforeContextMenuEventArgs) Handles _WebView.BeforeContextMenu
            Dim tmpContextMenu As EO.WebBrowser.ContextMenu = DirectCast (e.Menu, EO.WebBrowser.ContextMenu)
            For xLoop As Integer = tmpContextMenu.Items.Count - 1 To 0 Step -1
                If tmpContextMenu.Items(xLoop).Text IsNot Nothing AndAlso tmpContextMenu.Items(xLoop).Text.ToUpper.Contains("&VIEW PAGE SOURCE") Then
                    tmpContextMenu.Items.Remove(tmpContextMenu.Items(xLoop))
                ElseIf tmpContextMenu.Items(xLoop).Text IsNot Nothing AndAlso tmpContextMenu.Items(xLoop).Text.ToUpper.Contains("&PRINT") Then
                    tmpContextMenu.Items.Remove(tmpContextMenu.Items(xLoop))
                End If
            Next
            Dim tmpMenuItem As New EO.WebBrowser.MenuItem()
            tmpContextMenu.Items.Add(New EO.WebBrowser.MenuItem("About", CommandIds.ViewSource))
        End SubSub


The code that handles _WebView.Command
Code: Visual Basic.NET
Private Sub _WebView_Command(sender As Object, e As CommandEventArgs) Handles _WebView.Command
            If e.CommandId = CommandIds.ViewSource AndAlso My.Computer.Keyboard.CtrlKeyDown AndAlso My.Computer.Keyboard.ShiftKeyDown Then
                e.Handled = True
                _WebView.HideDevTools()
                RaiseEvent LoadNewDebug(_WebView)
            ElseIf e.CommandId = CommandIds.ViewSource Then
                e.Handled = True
                Dim tmpFrmAbout As New frmAbout()
                Dim userAgent As String = "Browser: " & CType(_WebView.EvalScript("navigator.userAgent"), String)
                Dim dllVersion As String = ""
                Dim LicenseYear As String = ""
                Try
                    'dllVersion = "EO dll version: " & System.Reflection.AssemblyName.GetAssemblyName("EO.WebBrowser.dll").Version.ToString
                    dllVersion = "EO dll version: " & System.Reflection.AssemblyName.GetAssemblyName("EO.WebBrowser.dll").Version.ToString


                Catch x As System.IO.IOException
                    dllVersion = x.ToString
                Catch ex As Exception
                    dllVersion = ex.ToString
                End Try
                Try
                    LicenseYear = AddLicense.LicenseYear
                Catch ex As Exception
                    LicenseYear = ex.ToString
                End Try
                Dim strFixVersions As String = dllVersion & " (" & LicenseYear & ")" & NewLine &
                                              userAgent & NewLine &
                                              NewLine &
                                              "*******************************************************************" & NewLine &
                                              "3.14.2.1 Fixed Skillsoft Admin errors and now supports Skillsoft, Hotschedules, should be any web pages." & NewLine &
                                              "3.14.2.2 Fixed Print command showing About Form." & NewLine &
                                              "3.14.2.3 Fixed exception when showing about." & NewLine &
                                              "3.14.2.4 Delete Cache at startup." & NewLine &
                                              "3.14.3.0 Jump to 2018 and EO.Base.Runtime.EnableEOWP=True" & NewLine &
                                              "3.14.3.1 Moved Add License to DLL" & NewLine &
                                              "4.0.0.3  Jump to 2020" & NewLine &
                                              "*******************************************************************" & NewLine &
                                              "Power Status:" & NewLine &
                                              "  Battery Charge Status:" & SystemInformation.PowerStatus.BatteryChargeStatus.ToString & NewLine &
                                              "  Battery Full Lifetime:" & SystemInformation.PowerStatus.BatteryFullLifetime.ToString & NewLine &
                                              " Battery Life Remaining:" & SystemInformation.PowerStatus.BatteryLifeRemaining.ToString & NewLine &
                                              "   Battery Life Percent:" & SystemInformation.PowerStatus.BatteryLifePercent.ToString & NewLine &
                                              "      Power Line Status:" & SystemInformation.PowerStatus.PowerLineStatus.ToString & NewLine

                'Dim msTmp As New MenuStrip()
                'msTmp.Items.Add("test1", Nothing, AddressOf Me.WebTabPage_CopyURL)
                'msTmp.Items.Add("test2", Nothing, AddressOf Me.WebTabPage_CopyCommandLine)
                ''tmpFrmAbout.MainMenuStrip = msTmp
                'tmpFrmAbout.Menu = New MainMenu()
                'tmpFrmAbout.Menu.MenuItems.Add("Copy URL")
                'tmpFrmAbout.Menu.MenuItems.Add("Copy Command Line")
                tmpFrmAbout.SetText(strFixVersions)
                tmpFrmAbout.ShowDialog()
            End If
        End Sub
eo_support
Posted: Wednesday, July 8, 2020 1:36:12 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,217
Yes. That's correct. That's exactly what this method is for:

https://www.essentialobjects.com/doc/eo.webbrowser.commandids.registerusercommand.aspx

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.