2013-10-11 48 views
1

我有我的WinForms瀏覽器控件的3個上下文菜單。WinForm瀏覽器控件哪個元素被右鍵點擊?

BrowserImages,BrowserLinks和BrowserDefault。你猜 - - 映像是正確的,當文檔的空白區域是正確的

  • 鏈接點擊 當鏈接
  • 和圖像是正確的單擊時,顯示將顯示

    1. 默認加載點擊。

    當DocumentCompleted被激發我添加Document_ContextMenuShowing事件 - 該代碼是:

    /// <summary> 
        /// Displays the Correct Context Menu for the element that is being right clicked on 
        /// </summary> 
        /// <param name="sender"> 
        /// HTMLDocument: The content of the web browser when the right click was detected. 
        /// </param> 
        /// <param name="e"> 
        /// HtmlElementEventArgs: Used for getting the location of the mouse so we know where to display the Context Menu 
        /// </param> 
        void Document_ContextMenuShowing(object sender, HtmlElementEventArgs e) 
        { 
         var res = (HtmlDocument)sender; 
    
         if (res.ActiveElement.InnerHtml.ToLowerInvariant().Contains("img")) 
         { 
          cmsBrowserImages.Show(e.ClientMousePosition.X, e.ClientMousePosition.Y); 
         } 
         else if (res.ActiveElement.InnerHtml.ToLowerInvariant().Contains("href")) 
         { 
          cmsBrowserLinks.Show(e.ClientMousePosition.X, e.ClientMousePosition.Y); 
         } 
         else 
         { 
          cmsBrowserDefault.Show(e.ClientMousePosition.X, e.ClientMousePosition.Y); 
         } 
        } 
    

    是否還有更好的,更強大的(更好的工作)的方式來做到這一點? C#代碼首選,但VB.Net將beok,很容易重寫。

    感謝

  • 回答

    相關問題