Click here to Skip to main content
14,367,886 members

Advanced Bookmark Control

Rate this:
3.67 (2 votes)
Please Sign up or sign in to vote.
3.67 (2 votes)
31 Dec 2009CC (ASA 2.5)
Make Bookmarks (or Favorites) for your web browser
Image 1


As many Visual Studio programmers know, Microsoft has released an Internet Explorer-based Web Browser control with Visual Studio 2005 and more current versions.

The WebBrowser control it provided is a managed wrapper around the IE control found in earlier versions of Visual Studio (SHDocVW.DLL) that shows some functions that were a little easy to work with, whereas at the same time providing some functions that weren't exactly that easy to get at without hundreds of lines of coding and research.

The object of this article and the provided source code is to show you how to work with the provided WebBrowser control and use it to make bookmarks with your on-going Web Browser application.

Adding Bookmarks  

Image of the Add Bookmark Form

Select Case e.ClickedItem.Name
    Case "BookmarkThisPageToolStripMenuItem"
           My.Settings.Save() : My.Settings.Reload()
        Catch ex As Exception
         End Try

In this VB.NET code snippet, you see that by clicking the "Bookmark this Page" DropDownButton, you add the current URL of the Web Browser to both the My.Settings.Bookmarks (System.Collections.Specialized.StringCollection type) and the DropDownItems for the Bookmarks. The code was from "ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs", defining the "e" DIM.

Case "AddBookmarkToolStripMenuItem"
    Dim Bookmark As String = InputBox("Location of WebSite", _
    "Add Custom Bookmark", "http://www.")
    If Not Bookmark = "" Then
        My.Settings.Save() : My.Settings.Reload()
    End If 

Here you see how you add a custom bookmark, one that's not the current URL. The same method is used for adding the bookmark; the only difference is that this time we use an InputBox function that returns the string typed. 

Removing Bookmarks 

Image 3
If Not (ListBox1.Items.Count = 0) And Not _ 
       (ListBox1.SelectedIndices.Count = 0) Then
     Dim SI As Integer = ListBox1.SelectedIndex
     FrmMain.BookmarksDropDownButton.DropDownItems.RemoveAt(SI + 6)
     My.Settings.Save() : My.Settings.Reload()
 End If 

In the Edit Bookmarks form, there is the option of removing installed bookmarks (a ListBox contains current ones).  Using the "RemoveAt" method, we can accurately get rid of the selected bookmark, or ListBox1.SelectedIndex. When removing from a list of DropDownItems or ListBox, you have to properly see which index, NOT item, you want to remove (hint: the index value is always one less than the count value).

If Not (ListBox1.Items.Count = 0) Then
    If MessageBox.Show("Are you sure you want to remove all bookmarks?", _
                       "Clear Bookmarks", MessageBoxButtons.YesNo, _
                        MessageBoxIcon.Question) _
                        = Windows.Forms.DialogResult.Yes Then
         Do : FrmMain.BookmarksDropDownButton.DropDownItems.RemoveAt(6)
         Loop Until (FrmMain.BookmarksDropDownButton.DropDownItems.Count = 6)
         My.Settings.Save() : My.Settings.Reload()
     End If
End If 

In another option in the same form, you can remove all bookmarks, whose code is a little bit more textually complicated than the Remove code.  If the user replies to the message box as a "yes," the code will clear the contents of the My.Settings.Bookmarks file and the ListBox1.Items.  Here, we also use a "Do...Loop Until <condition>" statement.  In this case, it makes the DropDownButton's DropDownItems remove the 7th item (remember Count = Index + 1) until the number of remaining items is 6.  It is basically self-explanatory.


This is currently the first version of the Advanced Bookmark Control.

Another one will be released as an Intermediate level article.  


This article, along with any associated source code and files, is licensed under The Creative Commons Attribution-ShareAlike 2.5 License


About the Author

Software Developer
United States United States
No Biography provided

Comments and Discussions

GeneralA good Bookmark Control Pin
yyhotspring30-Dec-09 18:29
memberyyhotspring30-Dec-09 18:29 
GeneralSPAM! Pin
sam.hill30-Dec-09 19:52
membersam.hill30-Dec-09 19:52 
GeneralRe: SPAM! Pin
VisualBas0831-Dec-09 8:57
memberVisualBas0831-Dec-09 8:57 
GeneralRe: SPAM! Pin
sam.hill31-Dec-09 9:01
membersam.hill31-Dec-09 9:01 
GeneralRe: SPAM! Pin
VisualBas0831-Dec-09 11:32
memberVisualBas0831-Dec-09 11:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Posted 30 Dec 2009


17 bookmarked