今天看了一篇關於『如何建立 IE 的右鍵選單(Context Menu)』的文章, 網址如下:
http://www.codeproject.com/KB/menus/IE_Context_Menu_Installer.aspx
它是以C#安裝專案為例子, 說明如何建立右鍵選單, 我試著以VB.NET直接產生右鍵選單, 效果還不錯, 步驟如下:
- 建立VB.NET 2005視窗專案
- 在Form1放入兩個Button
- 打開『程式碼檢視』, 輸入下列程式
- 再產生一個檔action.htm, 放在執行目錄中, 內容如下:
http://www.box.net/shared/nz3cngvsw0 - 按F5執行, 執行第一個按鈕
- 開啟一個新的IE, 選擇一段文字, 按右鍵, 即可看到Sample Action選單
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim mSubKey As Microsoft.Win32.RegistryKey = My.Computer.Registry.CurrentUser.CreateSubKey("SOFTWARE\Microsoft\Internet Explorer\MenuExt\Sample Action")
'1,2,4,8,10,20 in heximal are 1,2,4,8,16,32 in decimal (respectively)
' 0x1:Default, 0x2:Images, 0x4:Controls, 0x8:Tables, 0x10:Text selection, 0x20:Anchor
Dim keyValueInt As String = "16"
mSubKey.SetValue("Contexts", Convert.ToInt32(keyValueInt), Microsoft.Win32.RegistryValueKind.DWord)
mSubKey.SetValue(Nothing, "file://" & Application.StartupPath & "\action.htm")
mSubKey.Close()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
My.Computer.Registry.CurrentUser.DeleteSubKey("SOFTWARE\Microsoft\Internet Explorer\MenuExt\Sample Action")
End Sub
That's all, keep coding.
沒有留言:
張貼留言