How to Put a Favicon on Tabs in VB

Favicons are small 16-by-16 pixel images originally used by website designers to help users identify sites visually when browsing their bookmarks. As they are also displayed on a user's address bar and tabs, a well-designed favicon can help a website promote a brand image or idea. The favicon is stored as an icon file on the root of the hosting platform of a user, and it is the responsibility of the Internet browser to fetch and display the icon.

Instructions

    • 1

      Declare a new URI variable type using the Dim keyword to store the website address the favicon is going to be fetched from. As an example, this would be declared as "Dim URL as Uri = New Uri("www.example.com")." At the same time, create a local variable to hold the image, in the form "Dim webfavicon As Image."

    • 2

      Create a new HTTP request to fetch the icon, creating a file stream to read the favicon if the request is successful. The request should be made in the form "Dim faviconrequest As System.Net.Webrequest = HttpWebRequest.Create("http://" & URL.host & "/favicon.ico")." Open the file stream in the format "Dim faviconstream As IO.Stream = favicon.GetResponse.GetResponseStream."

    • 3

      Capture the favicon icon from the file stream and place it into the local image variable created earlier, through the expression "webfavicon = Image.FromStream(faviconstream)." This expression will either stream the favicon into the variable for later use or create a null assignment, equivalent to having nothing stored in the variable. Before attempting to draw the favicon image, consider using an "If webfavicon IsNot Nothing Then ..." statement to prevent any null object errors.

    • 4

      Open the vb.net form designer and create new tabpage and tabcontrol objects using the toolbox panel. Attach the tabpage to the tabcontrol via the expression "tabControl.Controls.Add(Me.tabPage)" followed by "tabControl.ImageList.Images.Add(webfavicon)" to draw the favicon onto the tab. Once you have set up the tabpage and tabcontrol objects through the designer, you can add new tabpages in your code, using the expression "Me.tabPagex = New System.Windows.Forms.TabPage()" and then attaching the tabpage as before.

    • 5

      Removing tabpages from a tabcontrol will not delete the old favicon in the ImageList, so call the method tabControl.ImageList.Images.Remove(index), where index refers to the number position of the favicon in the list, or use the .Clear() method to delete all the images in the list.

Related Searches:

References

Comments

Related Ads

Featured