Question

I have a top level (ie. acts like a window) UserControl (.NET 4.0) which I am using to simulate a custom form. I can easily set the title text and taskbar text like so:

public override string Text
{
    get { return base.Text; }
    set
    {
        base.Text = value
        TitleText.Text = value;
    }
}

Which sets both the title text and taskbar text:

What I have achieved so far

Please note that the bar down the bottom of the image is my actual taskbar; I have installed an alternate shell


The problem I have come across is that I can't seem to set the taskbar icon of this UserControl as it has no overridable Icon property so I can't set the taskbar icon as I would with the text. Please also note that the icon shown in the UserControl is just a PictureBox containing an image.

So, in short I want to be able to do this:

What I want to achieve

But I can't do this as there is no Icon property for a UserControl:

public override Icon Icon
{
    get { return base.Icon; }
    set
    {
         base.Icon = value;
         TitleBarIcon.Image = value.ToBitmap();
    }
}


How can I change the taskbar icon?
Thanks in advance ;)

Était-ce utile?

La solution

I am not sure if I got you right but I think you have to possibilites:

Either set the Icon of the ParentForm.

Or set the ApplicationIcon as described here: http://msdn.microsoft.com/en-us/library/339stzf7.aspx

EDIT:

As you are using a control as TopLevelControl you need to send the WM_SETICON during the creation of the control - as the form does!

Taken from the Form.CreateHandle:

        Icon icon = this.Icon;
        if (icon != null && this.TaskbarOwner.Handle != IntPtr.Zero)
        {
            UnsafeNativeMethods.SendMessage(this.TaskbarOwner, 128, 1, icon.Handle);
        }
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top