SIGN UP MEMBER LOGIN:    
ARTICLE

Loading a Form Icon

Posted by Mahesh Chand Articles | Windows Forms C# March 13, 2001
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.
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:

System.Resources.ResourceManager resources = new System.Resources.ResourceManager (typeof(Form1));
this.Icon = (System.Drawing.Icon) resources.GetObject ("$this.Icon");

Creating an Icon Object at run-time

You can 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.

System.Drawing.Icon ico = new System.Drawing.Icon("c:\\temp\\tst.ico");
this.Icon = ico ;

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

Login to add your contents and source code to this article
share this article :
post comment
 

You use Icon property of Window.

Here is code in WPF:

// Set an icon using code
Uri iconUri = new Uri("pack://application:,,,/WPFIcon2.ico", UriKind.RelativeOrAbsolute);
this.Icon = BitmapFrame.Create(iconUri);

Posted by Mahesh Chand Aug 28, 2009

How to add Form ICON in WPF

Posted by kalit sikka Aug 25, 2009
6 Months Free & No Setup Fees ASP.NET Hosting!
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!
Become a Sponsor