Following Leniel's answer, I wanted to do this in a C # winforms application. The link that he posted is C ++ .. Essentially, here you need the code you need if you want to do it in C #:
[DllImport("kernel32.dll", SetLastError = true)] static extern bool SetConsoleIcon(IntPtr hIcon);
and name it as follows:
public static void SetConsoleIcon(System.Drawing.Icon icon) { SetConsoleIcon(icon.Handle); }
I have a ConsoleWindow class that I use in a winforms application, which also makes it possible to display a console window. Here is the full def class
class ConsoleWindow { [DllImport("kernel32.dll", SetLastError = true)] static extern bool AllocConsole(); [DllImport("kernel32.dll")] static extern bool AttachConsole(int dwProcessId); private const int ATTACH_PARENT_PROCESS = -1; [DllImport("kernel32.dll")] static extern IntPtr GetConsoleWindow(); [DllImport("user32.dll")] static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] static extern bool SetWindowText(IntPtr hwnd, String lpString); [DllImport("user32.dll")] static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert); [DllImport("user32.dll")] static extern bool EnableMenuItem(IntPtr hMenu, uint uIDEnableItem, uint uEnable); [DllImport("kernel32.dll", SetLastError = true)] static extern bool SetConsoleIcon(IntPtr hIcon); const int SW_HIDE = 0; const int SW_SHOW = 5; const int SC_CLOSE = 0xF060; const int MF_GRAYED = 1; public static void AttachConsoleWindow() {
source share