Hello,
I just started out with Windows.Forms and was going through the MS
tutorials.
In the tutorial where you can create a non-rectangular shaped window by
using your own window painted with some paint utility, I am having some
problems with trying to compare the color of the pixel that I retrieve using
Bitmap.GetPixel(...) method.

My pseudo-code looks like this:
****************************************************************************
******
OnMouse_Click(...)
{
Color myColor = Bitmap.GetPixel(e.X, e.Y);
Color colorToCompare = Color.LightBlue; // At this point I notice
that the colorToCompare variable has a value of RGB{0x0}???!!! why?

if (myColor == colorToCompare)
// then execute logic which never does.
}
****************************************************************************
*******

I have another question. The reason I am trying to get the color of the
pixel is because I want to allow a mousemove event only when the user clicks
the mouse on the visible region of my form and not on its transparent
background. But I still have the problem that when a user clicks on the
transparent background of my window the icons (e.g.) that I see on that
position are not chosen? How can I choose the background items on a desktop
or if there is another application on the background when a user clicks on
the transparent background of my form?
--
Regards,
Sami

[Remove Numbers from e-mail address to use it]

Re: (Color myColor = Color.LightBlue) returns value RGB{0x0}??? by Morten

Morten
Thu Jan 27 04:28:46 CST 2005

Hi Sami,

There are two possible solutions for the colors not being equal.
1: myColor isn't LightBlue
2: myColor has a different alpha value than 255, which it probably might
if the image contains transparent parts.

To ignore the alpha value you can just check for

if(myColor.R == colorToCompare.R && myColor.G == colorToCompare.G &&
myColor.B == colorToCompare.B)
{
//the colors are sort of the same
}

As for the second question, I never had a problem with clicking on a
transparent part of my form not falling through. Not sure what kind of
transparency you are using, try setting the form's TransparencyKey
property to the same color as the form's backcolor. Use the same
backcolor for your image's Transparency (I never tried transparent forms
with bitmaps though, so I'm not sure they would work).


On Thu, 27 Jan 2005 10:51:16 +0100, Sami <s8a2m9i1_i5s1l9a6m@hotmail.com>
wrote:

> Hello,
> I just started out with Windows.Forms and was going through the MS
> tutorials.
> In the tutorial where you can create a non-rectangular shaped window by
> using your own window painted with some paint utility, I am having some
> problems with trying to compare the color of the pixel that I retrieve
> using
> Bitmap.GetPixel(...) method.
>
> My pseudo-code looks like this:
> ****************************************************************************
> ******
> OnMouse_Click(...)
> {
> Color myColor = Bitmap.GetPixel(e.X, e.Y);
> Color colorToCompare = Color.LightBlue; // At this point I notice
> that the colorToCompare variable has a value of RGB{0x0}???!!! why?
>
> if (myColor == colorToCompare)
> // then execute logic which never does.
> }
> ****************************************************************************
> *******
>
> I have another question. The reason I am trying to get the color of the
> pixel is because I want to allow a mousemove event only when the user
> clicks
> the mouse on the visible region of my form and not on its transparent
> background. But I still have the problem that when a user clicks on the
> transparent background of my window the icons (e.g.) that I see on that
> position are not chosen? How can I choose the background items on a
> desktop
> or if there is another application on the background when a user clicks
> on
> the transparent background of my form?



--
Happy Coding!
Morten Wennevik [C# MVP]

Re: (Color myColor = Color.LightBlue) returns value RGB{0x0}??? by Sami

Sami
Thu Jan 27 04:44:33 CST 2005

Hello,
Thanks for the prompt reply.
I might not have been very clear.

My first question was why I get a value of RGB{0x0} for Color.LightBlue (or
any other colour for that matter). Shouldn't it give me a valid RGB value?

As for the second question, I still don't understand your answer.
I am using a non-rectangular bitmap as the background for my form. Then I
set the Transparency Key Property of my form to the same colour as the
background colour of my bitmap image. By default I don't fall through. e.g.
if I have my form directly on top of the desktop I am able to see other app
icons through the transparent background of my form but am unable to start
the apps by double-clicking on them which makes sense since I didn't tell my
code to do that. How would I do that programmatically?

--
Regards,
Sami

[Remove Numbers from e-mail address to use it]
"Morten Wennevik" <MortenWennevik@hotmail.com> schrieb im Newsbeitrag
news:opsk9bd8ygklbvpo@pbn_computer...
> Hi Sami,
>
> There are two possible solutions for the colors not being equal.
> 1: myColor isn't LightBlue
> 2: myColor has a different alpha value than 255, which it probably might
> if the image contains transparent parts.
>
> To ignore the alpha value you can just check for
>
> if(myColor.R == colorToCompare.R && myColor.G == colorToCompare.G &&
> myColor.B == colorToCompare.B)
> {
> //the colors are sort of the same
> }
>
> As for the second question, I never had a problem with clicking on a
> transparent part of my form not falling through. Not sure what kind of
> transparency you are using, try setting the form's TransparencyKey
> property to the same color as the form's backcolor. Use the same
> backcolor for your image's Transparency (I never tried transparent forms
> with bitmaps though, so I'm not sure they would work).
>
>
> On Thu, 27 Jan 2005 10:51:16 +0100, Sami <s8a2m9i1_i5s1l9a6m@hotmail.com>
> wrote:
>
> > Hello,
> > I just started out with Windows.Forms and was going through the MS
> > tutorials.
> > In the tutorial where you can create a non-rectangular shaped window by
> > using your own window painted with some paint utility, I am having some
> > problems with trying to compare the color of the pixel that I retrieve
> > using
> > Bitmap.GetPixel(...) method.
> >
> > My pseudo-code looks like this:
> >
****************************************************************************
> > ******
> > OnMouse_Click(...)
> > {
> > Color myColor = Bitmap.GetPixel(e.X, e.Y);
> > Color colorToCompare = Color.LightBlue; // At this point I notice
> > that the colorToCompare variable has a value of RGB{0x0}???!!! why?
> >
> > if (myColor == colorToCompare)
> > // then execute logic which never does.
> > }
> >
****************************************************************************
> > *******
> >
> > I have another question. The reason I am trying to get the color of the
> > pixel is because I want to allow a mousemove event only when the user
> > clicks
> > the mouse on the visible region of my form and not on its transparent
> > background. But I still have the problem that when a user clicks on the
> > transparent background of my window the icons (e.g.) that I see on that
> > position are not chosen? How can I choose the background items on a
> > desktop
> > or if there is another application on the background when a user clicks
> > on
> > the transparent background of my form?
>
>
>
> --
> Happy Coding!
> Morten Wennevik [C# MVP]



Re: (Color myColor = Color.LightBlue) returns value RGB{0x0}??? by Sami

Sami
Thu Jan 27 04:50:37 CST 2005

Another question that i have is whether there is any way to obtain the
PixelColor without using the Bitmap object?
e.g. How would I obtain the pixel color on a point on a form if I am not
using any bitmaps as the background image on a form.

--
Regards,
Sami

[Remove Numbers from e-mail address to use it]
"Sami" <s8a2m9i1_i5s1l9a6m@hotmail.com> schrieb im Newsbeitrag
news:OuKCWVFBFHA.2012@TK2MSFTNGP15.phx.gbl...
> Hello,
> I just started out with Windows.Forms and was going through the MS
> tutorials.
> In the tutorial where you can create a non-rectangular shaped window by
> using your own window painted with some paint utility, I am having some
> problems with trying to compare the color of the pixel that I retrieve
using
> Bitmap.GetPixel(...) method.
>
> My pseudo-code looks like this:
>
****************************************************************************
> ******
> OnMouse_Click(...)
> {
> Color myColor = Bitmap.GetPixel(e.X, e.Y);
> Color colorToCompare = Color.LightBlue; // At this point I notice
> that the colorToCompare variable has a value of RGB{0x0}???!!! why?
>
> if (myColor == colorToCompare)
> // then execute logic which never does.
> }
>
****************************************************************************
> *******
>
> I have another question. The reason I am trying to get the color of the
> pixel is because I want to allow a mousemove event only when the user
clicks
> the mouse on the visible region of my form and not on its transparent
> background. But I still have the problem that when a user clicks on the
> transparent background of my window the icons (e.g.) that I see on that
> position are not chosen? How can I choose the background items on a
desktop
> or if there is another application on the background when a user clicks on
> the transparent background of my form?
> --
> Regards,
> Sami
>
> [Remove Numbers from e-mail address to use it]
>
>



Re: (Color myColor = Color.LightBlue) returns value RGB{0x0}??? by =?ISO-8859-2?Q?Marcin_Grz=EAbski?=

=?ISO-8859-2?Q?Marcin_Grz=EAbski?=
Thu Jan 27 05:05:35 CST 2005

Hi Sami,

> Another question that i have is whether there is any way to obtain the
> PixelColor without using the Bitmap object?
> e.g. How would I obtain the pixel color on a point on a form if I am not
> using any bitmaps as the background image on a form.

The "GetPixel" is a method of "Bitmap" class so you cannot use
it without "Bitmap" instance.
Some time ago i found a way to copy form (image) into the Bitmap,
but that solution needs "DllImport" of gdi32.dll.

HTH
Marcin