Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Get image from MessageBoxIcon

1 view
Skip to first unread message

Rui Oliveira

unread,
May 12, 2008, 2:16:01 PM5/12/08
to
I want use icons available in MessageBoxIcon to use them in a PictureBox
control.

How can I do this?

There are a way to get this icons from MessageBoxIcon, or I need to have
this images saved in a files to use them in a PictureBox control?

Thks,
Rui Oliveira

Paul E Collins

unread,
May 12, 2008, 3:43:35 PM5/12/08
to
"Rui Oliveira" <RuiOl...@discussions.microsoft.com> wrote:

> I want use icons available in MessageBoxIcon to use them in a
> PictureBox control.

Use the SystemIcons class.

Eq.


Ignacio Machin ( .NET/ C# MVP )

unread,
May 12, 2008, 3:56:39 PM5/12/08
to
On May 12, 2:16 pm, Rui Oliveira

Hi,

I do not think you can do that, that is simply an enumerator.
You have two options:
1- Take a peek in the code of MessageBox control and see how/from
where it gets the image from.
2- Copy the image you want and create your own copy of it. You can use
Print Screen, msPaint to sae just the piece you need.

Ignacio Machin ( .NET/ C# MVP )

unread,
May 12, 2008, 4:00:04 PM5/12/08
to
On May 12, 3:43 pm, "Paul E Collins" <find_my_real_addr...@CL4.org>
wrote:

> "Rui Oliveira" <RuiOlive...@discussions.microsoft.com> wrote:
> > I want use icons available in MessageBoxIcon to use them in a
> > PictureBox control.
>
> Use the SystemIcons class.
>
> Eq.

That is also possible, in this case you would have to convert it to a
bitmap:


myPictureBox.Image = Bitmap.FromHicon(SystemIcons.Hand.Handle);

Paul E Collins

unread,
May 12, 2008, 4:43:38 PM5/12/08
to
"Ignacio Machin ( .NET/ C# MVP )" <ignacio...@gmail.com> wrote:

> That is also possible, in this case you would have to convert it to a
> bitmap:
> myPictureBox.Image = Bitmap.FromHicon(SystemIcons.Hand.Handle);

But then you lose the transparent background and get ugly black edges.
Here's what I use (in the Paint method):

e.Graphics.DrawIcon(SystemIcons.Exclamation, 0, 0);

Eq.


Peter Duniho

unread,
May 12, 2008, 5:32:41 PM5/12/08
to
On Mon, 12 May 2008 13:43:38 -0700, Paul E Collins
<find_my_re...@CL4.org> wrote:

> "Ignacio Machin ( .NET/ C# MVP )" <ignacio...@gmail.com> wrote:
>
>> That is also possible, in this case you would have to convert it to a
>> bitmap:
>> myPictureBox.Image = Bitmap.FromHicon(SystemIcons.Hand.Handle);
>
> But then you lose the transparent background and get ugly black edges.

Really? That's annoying. I would have expected FromHicon() to include
alpha in the new Bitmap so that the transparency isn't lost.

One _should_ still be able to do it though, by making a regular 32bpp
Bitmap, clearing it with Color.Transparent, and then drawing the icon into
it with DrawIcon(). Then you only have to do it once, rather than
overriding OnPaint() or handling the Paint event.

Pete

Paul E Collins

unread,
May 12, 2008, 6:16:29 PM5/12/08
to
"Peter Duniho" <NpOeS...@nnowslpianmk.com> wrote:

> > But then you lose the transparent background and get ugly black
> > edges.
>
> Really? That's annoying. I would have expected FromHicon() to
> include alpha in the new Bitmap so that the transparency isn't lost.

The 100% transparent parts are okay, but the translucency isn't, so the
"drop shadow" comes out as pure black instead of a soft fade. (That's in
VS2005, anyway.)

Eq.


0 new messages