- This topic shows how to display windows icon in C# programming.
- Display windows icon in C# is done with the help of System.Drawing Class.
System.Drawing NameSpace – How to display windows icon in C#
- The System.Drawing namespace provides access to GDI+ basic graphics functionality.
- More advanced functionality is provided in the System.Drawing.Drawing2D, System.Drawing.Imaging, and System.Drawing.Text namespaces.
- The Graphics class provides methods for drawing to the display device.
- Classes such as Rectangle and Point encapsulate GDI+ primitives.
- The Pen class is used to draw lines and curves, while classes derived from the abstract class Brush are used to fill the interiors of shapes.
Graphics Class – How to display windows icon in C#
- Graphics class encapsulates a GDI+ drawing surface. This class cannot be inherited.
- Syntax
|
1 2 |
public sealed class Graphics : MarshalByRefObject, IDeviceContext, IDisposable |
Graphics.DrawIcon Method – How to display windows icon in C#
- Graphics.DrawIcon method is used to draw the image represented by the specified Icon at the specified coordinates.
Graphics.Drawicon Method (Icon, Rectangle) – How to display windows icon in C#
- Draws the image represented by the specified Icon within the area specified by a Rectangle structure.
- Syntax
|
1 2 3 4 |
public void DrawIcon( Icon icon, Rectangle targetRect ) |
- Icon – Targeted icon
- Rectangle – Rectangle structure that specifies the location and size of the resulting image on the display surface. The image contained in the icon parameter is scaled to the dimensions of this rectangular area.
Graphics.Drawicon Method (Icon, Int32, Int32) – How to display windows icon in C#
- Draws the image represented by the specified Icon at the specified coordinates.
- Syntax
|
1 2 3 4 5 |
public void DrawIcon( Icon icon, int x, int y ) |
How to display windows icon in C# – Complete Code
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace testc { public partial class Form1 : Form { Graphics gr_graphics = default(Graphics); //need a pen for drawing and make it black Pen pen_draw = new Pen(Color.Black); public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } private void Form1_Paint(object sender, PaintEventArgs e) { gr_graphics = e.Graphics; //draw an ellipse gr_graphics.DrawIcon (this.Icon ,90,120); } } } |
How to display windows icon in C# – windows icon
How to display windows icon in C#


