首页 > 解决方案 > Closing dropdown menustrip in webview2

问题描述

I have in a desktop application a webpage with a menustrip. I use webview2 as webbrowser control. When i click on the menustrip the menu dropsdown. The problem is that the dropdown doesn’t hide when i click on the webpage. In the standard vb net webbrowser this is not happening. So how can i hide the dropdown menu in webview2?

Maybe the answer lies in VB net. I am looking for a method to close the dropdown of the menustrip of my form i can call than this method from javascript on my webpage

标签: vb.netwebview2

解决方案


感谢 Jimi 和 Poul 我解决了这个问题。这对你来说很简单。解决方案: 1 我的网页是 openlayers 地图,其中有一个 eventlistner 供点击,

map.on('singleclick', function (event) {
    var lonLat = ol.proj.toLonLat(event.coordinate);
    var str = lonLat[0] + "," + lonLat[1];

(window.chrome.webview.hostObjects.sync.Bridge).Map_click(str);

});

vb net 2. 我使用 vb net 和 javascript WebView21.CoreWebView2.AddHostObjectToScript("Bridge", New Bridge()) 之间的桥梁,在我的 vb net 桌面应用程序和 Webppage 上的 javascript 之间架起一座桥梁。

3 我遍历菜单项并隐藏菜单项的下拉菜单

Private Sub clearmenustrip() For Each mnuitem As System.Windows.Forms.ToolStripMenuItem In Fmenu.MenuStrip1.Items
        mnuitem.HideDropDown()
    Next
End Sub 

MenuStrip1 是表单中的菜单条


推荐阅读