Click here to Skip to main content
12,885,684 members (38,224 online)
Click here to Skip to main content
Add your own
alternative version


17 bookmarked
Posted 30 Dec 2009

Advanced Bookmark Control

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


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 

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

You may also be interested in...


Comments and Discussions

GeneralA good Bookmark Control Pin
yyhotspring30-Dec-09 17:29
memberyyhotspring30-Dec-09 17:29 
GeneralSPAM! Pin
sam.hill30-Dec-09 18:52
membersam.hill30-Dec-09 18:52 
GeneralRe: SPAM! Pin
iSurf Elite Company31-Dec-09 7:57
memberiSurf Elite Company31-Dec-09 7:57 
GeneralRe: SPAM! Pin
sam.hill31-Dec-09 8:01
membersam.hill31-Dec-09 8:01 
GeneralRe: SPAM! Pin
iSurf Elite Company31-Dec-09 10:32
memberiSurf Elite Company31-Dec-09 10: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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170424.1 | Last Updated 31 Dec 2009
Article Copyright 2009 by VisualBas08
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid