Detecting Transparent as a color

J

jcrouse

I am using the following code to move a label on a form at runtime:

If myMousedown = lblP1JoyRight.Name Then

If lblP1JoyRight.BackColor.Equals(Color.Transparent) Then

bTransCk = True

lblP1JoyRight.BackColor = clrLabelMove

End If

lblP1JoyRight.Location = New System.Drawing.Point(Cursor.Position.X -
mouseX, Cursor.Position.Y - mouseY)

bMouseMove = True

End If


I am attempting to see if the labels background color is transparent. If it
is, I want to set a flag (bTransCk), change it to a color a users has
selected under the options menu (clrLabelMove), move the control (while it
is using the user selected backcolor, "clrLabelMove"), then set it back to
transparent after the move is complete. Transparency seems to really draw on
system resources while dragging a control. Anyways, the problem is that the
control won't seem to detect as transparent even though it is. If I have a
picture for my background on my form I can see through the label. If I drag
the label I can see through it while dragging it. But it just won't detect
as transparent. I am able to change the label background colors at runtime
with code. The funny thing is that if I select the label and set it's
background to transparent using a menu option I have, it then detects it as
transparent during the mouse_move event. I must be checking with the wrong
syntax or not handling the color properly. Any ideas here?

Thanks,
John
 
J

jcrouse

More information:

I am creating layouts, saving them and reopening them. I store the
information in XML files. I use this code to write to the XML file:

dr1("BackColor") = lblP1JoyUp.BackColor.ToArgb



This is how it stores it:

<BackColor>16777215</BackColor>





And I read it back in using this code:

lblP1JoyUp.BackColor = Color.FromArgb(ds.Tables(0).Rows(0).Item(6))



Thanks,
John
 
T

The Grim Reaper

You can't detect a transparent pixel - the OS doesn't draw it - hence it
being transparent!!
You'll only be able to detect the pixel "underneath".
_______________________________
The Grim Reaper
 
M

Mick Doherty

Color.Transparent in dotnet is White with no Alpha (&H00FFFFFF).
Transparent pixels in a bitmap are 0 (&H00000000) or Black with no Alpha.
So you must check for both Color.Transparent and 0.

How are you detecting the backcolor of the label?
 
J

jcrouse

Resolved! I forced it to transparent with this code:

If ds.Tables(0).Rows(0).Item(6) = "16777215" Then

lblP1JoyUp.BackColor = Color.Transparent

Else

lblP1JoyUp.BackColor = Color.FromArgb(ds.Tables(0).Rows(0).Item(6))

End If


I'm still not sure why this was necessary though.

Thnaks,
John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top