FryedMan
FryedMan

Reputation: 25

How to set the window's icon

I was wondering how you would set the icon for the window in c#. I have found answers, but the answer does not involve programming. In visual studio they have an application builder, but I would like to program my application instead. Does anyone know who to accomplish this simple task?

This is what I have so far:

class Program
{
    public static void Main(string[] args)
    {
        Application.Run(new window());
    }
}

class Window : System.Windows.Forms.Form
{
    public static String Title = "This is a title!";

    public Window()
    {
        this.Size = new Size(640, 480);
        this.Text = Title;
    }
}

Upvotes: 0

Views: 251

Answers (2)

Avi Turner
Avi Turner

Reputation: 10456

You can do it using the designer:

  1. Open the designer.
  2. Click on the window.
  3. Open Properties pane (F4).
  4. Locate the Icon row and click on it.
  5. Click on the ... Button.

enter image description here

Alternativaly, you can do it in code:

string pathToIcon =@"C:\Path\To\Icon.ico"
this.Icon = new Icon(pathToIcon );

Upvotes: 1

DoronG
DoronG

Reputation: 2663

this.Icon = new Icon(@"C:\Folder\IconName.ico");

or if you are embedding the icon in the app:

this.Icon = new Icon(iconStream);

Upvotes: 1

Related Questions