ARTICLE

Loading a Form Icon in VB.NET

Posted by Mahesh Chand Articles | Visual Basic 2010 September 05, 2003
In this article, I will show you how to load an icon of a Form programmatically.
 
Reader Level:

In .NET framework, the Icon class represents a Windows icon, which is a small bitmap image used to represent an object. The icon class is defined in System.Drawing namespace. So before using Icon class, you need to reference the System.Drawing namespace to your application.

You can set icon of a form at run-time as well as at design-time. You use a form's Icon property to set form's icon at design-time. Which actually adds two lines to your source code:

Dim resources As New System.Resources.ResourceManager(GetType(Form1))
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)

Creating an Icon Object at run-time.

You can create an icon object at run-time and set it as icon of a Form. You use Icon constructor to create an icon object. The Icon constructor is an overloaded method:

In this sample example, I load tst.ico file as an icon of the form.

Dim ico As New System.Drawing.Icon("c:\temp\tst.ico")
Me.Icon = ico

You can even set icon's size by using other overloaded constructors.

share this article :
post comment
 
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Team Foundation Server Hosting
Become a Sponsor