By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,263 Members | 2,640 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,263 IT Pros & Developers. It's quick & easy.

Q: Transparent image on a form

P: n/a
Hi

Can anybody help me with the following? It is driving me crazy!!!

I'm trying to produce a non-rectangular form as follows:

(1) Produce a bitmap e.g. gif, using paint shop pro 5.
(2) The Background color of the bitmap is set to white.
(3) Draw a design on the bitmap in a color other than white.
(4) Create a windows application.
(5) Set the forms background image to be the bitmap created earlier.
(6) Set the transparencyKey of the form to be white i.e. the same as the
background color of the bitmap.
(7) Set the FormBorderStyle to None
(8) Run the application.

I expected just the non-white images but instead I still see the white
background! D'OH!!!

Can anybody tell me what I'm doing wrong?

Here's a link to Microsoft describing the same thing.

Thanks in adavance

Geoff
Nov 21 '05 #1
Share this Question
Share on Google+
40 Replies


P: n/a
Whoops, sorry, here's the link to Microsoft:

http://msdn.microsoft.com/library/de...ndowsforms.asp

Geoff

"Geoff Jones" <no********@email.com> wrote in message
news:41***********************@news.dial.pipex.com ...
Hi

Can anybody help me with the following? It is driving me crazy!!!

I'm trying to produce a non-rectangular form as follows:

(1) Produce a bitmap e.g. gif, using paint shop pro 5.
(2) The Background color of the bitmap is set to white.
(3) Draw a design on the bitmap in a color other than white.
(4) Create a windows application.
(5) Set the forms background image to be the bitmap created earlier.
(6) Set the transparencyKey of the form to be white i.e. the same as the
background color of the bitmap.
(7) Set the FormBorderStyle to None
(8) Run the application.

I expected just the non-white images but instead I still see the white
background! D'OH!!!

Can anybody tell me what I'm doing wrong?

Here's a link to Microsoft describing the same thing.

Thanks in adavance

Geoff

Nov 21 '05 #2

P: n/a
"Geoff Jones" <no********@email.com> schrieb:
I'm trying to produce a non-rectangular form as follows:

(1) Produce a bitmap e.g. gif, using paint shop pro 5.
(2) The Background color of the bitmap is set to white.
(3) Draw a design on the bitmap in a color other than white.
(4) Create a windows application.
(5) Set the forms background image to be the bitmap created earlier.
(6) Set the transparencyKey of the form to be white i.e. the same as the
background color of the bitmap.
(7) Set the FormBorderStyle to None
(8) Run the application.

I expected just the non-white images but instead I still see the white
background! D'OH!!!


You may want to use regions instead:

Region from Bitmap
<URL:http://www.bobpowell.net/region_from_bitmap.htm>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #3

P: n/a
Hi, I also got this problem before, this following VB code may help:)

Public Sub SetBackgroundBitmap(ByVal image As Image, ByVal
transparencyColor As Color)

Me.backgroundImage = New Bitmap(image)
Width = Me.backgroundImage .Width
Height = Me.backgroundImage .Height
Region = BitmapToRegion(Me.backgroundImage, transparencyColor)

End Sub
"Herfried K. Wagner [MVP]" <hi***************@gmx.at>
??????:%2****************@tk2msftngp13.phx.gbl...
"Geoff Jones" <no********@email.com> schrieb:
I'm trying to produce a non-rectangular form as follows:

(1) Produce a bitmap e.g. gif, using paint shop pro 5.
(2) The Background color of the bitmap is set to white.
(3) Draw a design on the bitmap in a color other than white.
(4) Create a windows application.
(5) Set the forms background image to be the bitmap created earlier.
(6) Set the transparencyKey of the form to be white i.e. the same as the
background color of the bitmap.
(7) Set the FormBorderStyle to None
(8) Run the application.

I expected just the non-white images but instead I still see the white
background! D'OH!!!


You may want to use regions instead:

Region from Bitmap
<URL:http://www.bobpowell.net/region_from_bitmap.htm>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #4

P: n/a
Geoff,

I never understood this questions.

Is it something that you want to resize the picturebox to the size of the
image when that is smaller than the picturebox?

Or something I did in this as my sample in this message?
http://groups-beta.google.com/group/...7cab2e04089f27
Cor

"Geoff Jones" <no********@email.com> > Whoops, sorry, here's the link to
Microsoft:

http://msdn.microsoft.com/library/de...ndowsforms.asp

Geoff

"Geoff Jones" <no********@email.com> wrote in message
news:41***********************@news.dial.pipex.com ...
Hi

Can anybody help me with the following? It is driving me crazy!!!

I'm trying to produce a non-rectangular form as follows:

(1) Produce a bitmap e.g. gif, using paint shop pro 5.
(2) The Background color of the bitmap is set to white.
(3) Draw a design on the bitmap in a color other than white.
(4) Create a windows application.
(5) Set the forms background image to be the bitmap created earlier.
(6) Set the transparencyKey of the form to be white i.e. the same as the
background color of the bitmap.
(7) Set the FormBorderStyle to None
(8) Run the application.

I expected just the non-white images but instead I still see the white
background! D'OH!!!

Can anybody tell me what I'm doing wrong?

Here's a link to Microsoft describing the same thing.

Thanks in adavance

Geoff


Nov 21 '05 #5

P: n/a
Hi Cor

If you follow the instructions in the link I gave earlier, I'd be interested
to see if you have the same problem.

Geoff

"Cor Ligthert" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Geoff,

I never understood this questions.

Is it something that you want to resize the picturebox to the size of the
image when that is smaller than the picturebox?

Or something I did in this as my sample in this message?
http://groups-beta.google.com/group/...7cab2e04089f27
Cor

"Geoff Jones" <no********@email.com> > Whoops, sorry, here's the link to
Microsoft:

http://msdn.microsoft.com/library/de...ndowsforms.asp

Geoff

"Geoff Jones" <no********@email.com> wrote in message
news:41***********************@news.dial.pipex.com ...
Hi

Can anybody help me with the following? It is driving me crazy!!!

I'm trying to produce a non-rectangular form as follows:

(1) Produce a bitmap e.g. gif, using paint shop pro 5.
(2) The Background color of the bitmap is set to white.
(3) Draw a design on the bitmap in a color other than white.
(4) Create a windows application.
(5) Set the forms background image to be the bitmap created earlier.
(6) Set the transparencyKey of the form to be white i.e. the same as the
background color of the bitmap.
(7) Set the FormBorderStyle to None
(8) Run the application.

I expected just the non-white images but instead I still see the white
background! D'OH!!!

Can anybody tell me what I'm doing wrong?

Here's a link to Microsoft describing the same thing.

Thanks in adavance

Geoff



Nov 21 '05 #6

P: n/a
Geoff,

I once had the same thing and the problem wasn't in my code but in the
colordepth of my screen (right click desktop/properties/settings) , if I
set it to truecolors(24 bits) the transparencyKey didn't work, if I set it
to heigh colors (16 bit) it does work, maybe this helps you

greetz Peter

"zhang" <kz*****@yahoo.com> wrote in message
news:OA**************@TK2MSFTNGP15.phx.gbl...
Hi, I also got this problem before, this following VB code may help:)

Public Sub SetBackgroundBitmap(ByVal image As Image, ByVal
transparencyColor As Color)

Me.backgroundImage = New Bitmap(image)
Width = Me.backgroundImage .Width
Height = Me.backgroundImage .Height
Region = BitmapToRegion(Me.backgroundImage, transparencyColor)

End Sub
"Herfried K. Wagner [MVP]" <hi***************@gmx.at>
??????:%2****************@tk2msftngp13.phx.gbl...
"Geoff Jones" <no********@email.com> schrieb:
I'm trying to produce a non-rectangular form as follows:

(1) Produce a bitmap e.g. gif, using paint shop pro 5.
(2) The Background color of the bitmap is set to white.
(3) Draw a design on the bitmap in a color other than white.
(4) Create a windows application.
(5) Set the forms background image to be the bitmap created earlier.
(6) Set the transparencyKey of the form to be white i.e. the same as the background color of the bitmap.
(7) Set the FormBorderStyle to None
(8) Run the application.

I expected just the non-white images but instead I still see the white
background! D'OH!!!


You may want to use regions instead:

Region from Bitmap
<URL:http://www.bobpowell.net/region_from_bitmap.htm>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>


Nov 21 '05 #7

P: n/a
Geoff,

Did you see the message from Peter Proost
Otherwise it works for me.
(Therefore I find this useless this way)

I hope this helps anyway

Cor

"Geoff Jones" <no********@email.com>
Hi Cor

If you follow the instructions in the link I gave earlier, I'd be
interested to see if you have the same problem.

Geoff

"Cor Ligthert" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Geoff,

I never understood this questions.

Is it something that you want to resize the picturebox to the size of the
image when that is smaller than the picturebox?

Or something I did in this as my sample in this message?
http://groups-beta.google.com/group/...7cab2e04089f27
Cor

"Geoff Jones" <no********@email.com> > Whoops, sorry, here's the link to
Microsoft:

http://msdn.microsoft.com/library/de...ndowsforms.asp

Geoff

"Geoff Jones" <no********@email.com> wrote in message
news:41***********************@news.dial.pipex.com ...
Hi

Can anybody help me with the following? It is driving me crazy!!!

I'm trying to produce a non-rectangular form as follows:

(1) Produce a bitmap e.g. gif, using paint shop pro 5.
(2) The Background color of the bitmap is set to white.
(3) Draw a design on the bitmap in a color other than white.
(4) Create a windows application.
(5) Set the forms background image to be the bitmap created earlier.
(6) Set the transparencyKey of the form to be white i.e. the same as
the background color of the bitmap.
(7) Set the FormBorderStyle to None
(8) Run the application.

I expected just the non-white images but instead I still see the white
background! D'OH!!!

Can anybody tell me what I'm doing wrong?

Here's a link to Microsoft describing the same thing.

Thanks in adavance

Geoff



Nov 21 '05 #8

P: n/a
Hi Cor

With your, and others help (ta Peter), it now works :)

I had to change the display to 16 bit and also re-paint the background of
the image I was using with "White" i.e. I'm not sure it was "true white" in
the initial bitmap.

Great, it now works. HOWEVER, this restriction that it has to be less than
24 bit seems to be less than ideal. I don't know what depth the application
will be on the client machines! Surely there must be an easier way to do
this??? Am I right in assuming that even zhang's idea will not work on a 24
bit for the same reasons?

Geoff

"Cor Ligthert" <no************@planet.nl> wrote in message
news:Oa**************@TK2MSFTNGP12.phx.gbl...
Geoff,

Did you see the message from Peter Proost
Otherwise it works for me.
(Therefore I find this useless this way)

I hope this helps anyway

Cor

"Geoff Jones" <no********@email.com>
Hi Cor

If you follow the instructions in the link I gave earlier, I'd be
interested to see if you have the same problem.

Geoff

"Cor Ligthert" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Geoff,

I never understood this questions.

Is it something that you want to resize the picturebox to the size of
the image when that is smaller than the picturebox?

Or something I did in this as my sample in this message?
http://groups-beta.google.com/group/...7cab2e04089f27
Cor

"Geoff Jones" <no********@email.com> > Whoops, sorry, here's the link to
Microsoft:

http://msdn.microsoft.com/library/de...ndowsforms.asp

Geoff

"Geoff Jones" <no********@email.com> wrote in message
news:41***********************@news.dial.pipex.com ...
> Hi
>
> Can anybody help me with the following? It is driving me crazy!!!
>
> I'm trying to produce a non-rectangular form as follows:
>
> (1) Produce a bitmap e.g. gif, using paint shop pro 5.
> (2) The Background color of the bitmap is set to white.
> (3) Draw a design on the bitmap in a color other than white.
> (4) Create a windows application.
> (5) Set the forms background image to be the bitmap created earlier.
> (6) Set the transparencyKey of the form to be white i.e. the same as
> the background color of the bitmap.
> (7) Set the FormBorderStyle to None
> (8) Run the application.
>
> I expected just the non-white images but instead I still see the white
> background! D'OH!!!
>
> Can anybody tell me what I'm doing wrong?
>
> Here's a link to Microsoft describing the same thing.
>
> Thanks in adavance
>
> Geoff
>



Nov 21 '05 #9

P: n/a
Geoff,

Did you try my sample?

Cor
Nov 21 '05 #10

P: n/a
"Geoff Jones" <no********@email.com> schrieb:
I had to change the display to 16 bit and also re-paint the background of
the image I was using with "White" i.e. I'm not sure it was "true white"
in the initial bitmap.

Great, it now works. HOWEVER, this restriction that it has to be less than
24 bit seems to be less than ideal. I don't know what depth the
application will be on the client machines! Surely there must be an easier
way to do this??? Am I right in assuming that even zhang's idea will not
work on a 24 bit for the same reasons?


If you are using regions, the problems will go away. Regions will work on
any color depth.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #11

P: n/a
Geoff copy paste this to see how regions work.

Private Sub Form1_Paint(ByVal sender As Object, ByVal e As _
System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
Dim myGraphicsPath As Drawing2D.GraphicsPath = New _
Drawing2D.GraphicsPath()
myGraphicsPath.AddEllipse(New Rectangle(0, 0, 125, 125))
myGraphicsPath.AddEllipse(New Rectangle(75, 75, 20, 20))
myGraphicsPath.AddEllipse(New Rectangle(120, 0, 125, 125))
myGraphicsPath.AddEllipse(New Rectangle(145, 75, 20, 20))

Me.BackColor = Color.Chartreuse
Me.Size = New System.Drawing.Size(256, 256)
Me.Region = New Region(myGraphicsPath)

End Sub

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:eN**************@TK2MSFTNGP12.phx.gbl...
"Geoff Jones" <no********@email.com> schrieb:
I had to change the display to 16 bit and also re-paint the background of the image I was using with "White" i.e. I'm not sure it was "true white"
in the initial bitmap.

Great, it now works. HOWEVER, this restriction that it has to be less than 24 bit seems to be less than ideal. I don't know what depth the
application will be on the client machines! Surely there must be an easier way to do this??? Am I right in assuming that even zhang's idea will not
work on a 24 bit for the same reasons?


If you are using regions, the problems will go away. Regions will work on
any color depth.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #12

P: n/a
Hi Herfried

I'm trying to use your ideas for Regions. I have converted the GetRegion
code from C# to VB and have tried, but failed, to get it to do what I want
i.e. I am uncertain where to use the function etc. in the VB code.

I've tried the following:
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.Load

TheRegion = GetRegion(Me.BackgroundImage, Color.White)

Me.Region = TheRegion

End Sub

In the hope that it would just paint the image but not the white background.
Unfortunately, I get an overflow error. Can you help?

Geoff

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
"Geoff Jones" <no********@email.com> schrieb:
I'm trying to produce a non-rectangular form as follows:

(1) Produce a bitmap e.g. gif, using paint shop pro 5.
(2) The Background color of the bitmap is set to white.
(3) Draw a design on the bitmap in a color other than white.
(4) Create a windows application.
(5) Set the forms background image to be the bitmap created earlier.
(6) Set the transparencyKey of the form to be white i.e. the same as the
background color of the bitmap.
(7) Set the FormBorderStyle to None
(8) Run the application.

I expected just the non-white images but instead I still see the white
background! D'OH!!!


You may want to use regions instead:

Region from Bitmap
<URL:http://www.bobpowell.net/region_from_bitmap.htm>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #13

P: n/a
I'm guessing that GetRegion merely returns the regions to be painted? Is
this correct?

Geoff

"Geoff Jones" <no********@email.com> wrote in message
news:41*********************@news.dial.pipex.com.. .
Hi Herfried

I'm trying to use your ideas for Regions. I have converted the GetRegion
code from C# to VB and have tried, but failed, to get it to do what I want
i.e. I am uncertain where to use the function etc. in the VB code.

I've tried the following:
Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load

TheRegion = GetRegion(Me.BackgroundImage, Color.White)

Me.Region = TheRegion

End Sub

In the hope that it would just paint the image but not the white
background. Unfortunately, I get an overflow error. Can you help?

Geoff

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
"Geoff Jones" <no********@email.com> schrieb:
I'm trying to produce a non-rectangular form as follows:

(1) Produce a bitmap e.g. gif, using paint shop pro 5.
(2) The Background color of the bitmap is set to white.
(3) Draw a design on the bitmap in a color other than white.
(4) Create a windows application.
(5) Set the forms background image to be the bitmap created earlier.
(6) Set the transparencyKey of the form to be white i.e. the same as the
background color of the bitmap.
(7) Set the FormBorderStyle to None
(8) Run the application.

I expected just the non-white images but instead I still see the white
background! D'OH!!!


You may want to use regions instead:

Region from Bitmap
<URL:http://www.bobpowell.net/region_from_bitmap.htm>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>


Nov 21 '05 #14

P: n/a
"Geoff Jones" <no********@email.com> schrieb:
I'm guessing that GetRegion merely returns the regions to be painted? Is
this correct?


A region is used to represent an area of arbitrary shape. The form's
Region' property can be used to set the form's shape. I assume that there
is a bug in your 'GetRegion' function. Can you post your implementation?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #15

P: n/a
Thanks for looking at this for me Herfried. Here is my VB version:

Private Function GetRegion(ByRef _img As Bitmap, ByVal color As Color) As
Region

Dim _matchColor As Color = color.FromArgb(color.R, color.G, color.B)

Dim rgn As System.Drawing.Region = New Region

rgn.MakeEmpty()

Dim rc As Rectangle = New Rectangle(0, 0, 0, 0)

Dim inimage As Boolean = False

Dim x As Integer

Dim y As Integer

For y = 0 To _img.Height - 1

For x = 0 To _img.Width - 1

If Not (inimage) Then

If Not color.op_Equality(_img.GetPixel(x, y), _matchColor) Then

inimage = True

rc.X = x

rc.Y = y

rc.Height = 1

Else

inimage = False

rc.Width = x - rc.X

rgn.Union(rc)

End If

Else

inimage = False

rc.Width = _img.Width - rc.X

rgn.Union(rc)

End If

Next

Next

Return rgn

End Function

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:u$**************@TK2MSFTNGP10.phx.gbl...
"Geoff Jones" <no********@email.com> schrieb:
I'm guessing that GetRegion merely returns the regions to be painted? Is
this correct?


A region is used to represent an area of arbitrary shape. The form's
Region' property can be used to set the form's shape. I assume that there
is a bug in your 'GetRegion' function. Can you post your implementation?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #16

P: n/a
Hi again Herfried

After thinking about it, I'm not sure if the region that the code returns is
the "transparent area" i.e. white background in my case, or the region of
the bitmap I want displayed. Could you enlighten me?

In addition, am I calling this in the correct way i.e. does this next line
tell the application to only draw the region returned by the function?

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.Load

TheRegion = GetRegion(Me.BackgroundImage, Color.White)

Me.Region = TheRegion

End Sub

Note that I'm placing it in the Load member. Is this the correct place to
put it???

Thanks in advance

Geoff

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:u$**************@TK2MSFTNGP10.phx.gbl...
"Geoff Jones" <no********@email.com> schrieb:
I'm guessing that GetRegion merely returns the regions to be painted? Is
this correct?


A region is used to represent an area of arbitrary shape. The form's
Region' property can be used to set the form's shape. I assume that there
is a bug in your 'GetRegion' function. Can you post your implementation?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #17

P: n/a
Geoff,

Why you dont use the sample I showed you the only thing you have to do with
that is in my opinion to paste it in and than make another region.

So you make me curious.

Cor
Nov 21 '05 #18

P: n/a
"Cor Ligthert" <no************@planet.nl> schrieb:
Why you dont use the sample I showed you the only thing you have to do
with that is in my opinion to paste it in and than make another region.


I assume the OP wants to create a region from a bitmap.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #19

P: n/a
Yes, that's right.

Geoff

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:uK**************@TK2MSFTNGP10.phx.gbl...
"Cor Ligthert" <no************@planet.nl> schrieb:
Why you dont use the sample I showed you the only thing you have to do
with that is in my opinion to paste it in and than make another region.


I assume the OP wants to create a region from a bitmap.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #20

P: n/a
Herfried,
I assume the OP wants to create a region from a bitmap.


And did you give him a sample from that, because I have more the idea that
he wants to use a bitmap as a region.

Cor

Nov 21 '05 #21

P: n/a
Geoff
Yes, that's right.


I don't know what I did that you ignore me in this way, however when you
don't want my help than be so polite to answer that in an answer to me.

I will try to remember this in future and not bother you anymore.

Cor
Nov 21 '05 #22

P: n/a
Cor,

"Cor Ligthert" <no************@planet.nl> schrieb:
I assume the OP wants to create a region from a bitmap.


And did you give him a sample from that, because I have more the idea that
he wants to use a bitmap as a region.


As always, there is no guarantee that I provide sample code.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #23

P: n/a
Geoff,

"Geoff Jones" <no********@email.com> schrieb:
Thanks for looking at this for me Herfried. Here is my VB version:


Very quick and dirty, but seems to work:

\\\
Private Function GetRegion( _
ByVal _img As Bitmap, _
ByVal color As Color _
) As Region
Dim _matchColor As Color = _
color.FromArgb(color.R, color.G, color.B)
Dim rgn As System.Drawing.Region = New Region
rgn.MakeEmpty()
Dim rc As Rectangle = New Rectangle(0, 0, 0, 0)
Dim inimage As Boolean = False
Dim x As Integer
Dim y As Integer
For y = 0 To _img.Height - 1
For x = 0 To _img.Width - 1
If Not (inimage) Then
If _
Not color.op_Equality(_img.GetPixel(x, y), _matchColor)
_
Then
inimage = True
rc.X = x
rc.Y = y
rc.Height = 1
End If
Else
inimage = False
rc.Width = _img.Width - rc.X
rgn.Union(rc)
End If
Next
If inimage Then
inimage = False
rc.Width = _img.Width - rc.X
rgn.Union(rc)
End If
Next
Return rgn
End Function
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #24

P: n/a
Hi Cor

I'm afraid I don't know what I've done to upset you. I haven't been ignoring
you! I don't mean to be rude but sometimes I don't fully understand what you
are trying to explain to me. Is it possible that you are also
misunderstanding what I am asking.

I'm sorry again and if you re-read any of my posts you will see that I have
not written anything in a rude manner or indeed ignored you!

Geoff

"Cor Ligthert" <no************@planet.nl> wrote in message
news:OV**************@TK2MSFTNGP15.phx.gbl...
Geoff
Yes, that's right.


I don't know what I did that you ignore me in this way, however when you
don't want my help than be so polite to answer that in an answer to me.

I will try to remember this in future and not bother you anymore.

Cor

Nov 21 '05 #25

P: n/a
Many thanks Herfried, I will try your code (but first I'll try and
understand it - we live and learn eh?)

Many thanks

Geoff

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:u5**************@TK2MSFTNGP15.phx.gbl...
Geoff,

"Geoff Jones" <no********@email.com> schrieb:
Thanks for looking at this for me Herfried. Here is my VB version:


Very quick and dirty, but seems to work:

\\\
Private Function GetRegion( _
ByVal _img As Bitmap, _
ByVal color As Color _
) As Region
Dim _matchColor As Color = _
color.FromArgb(color.R, color.G, color.B)
Dim rgn As System.Drawing.Region = New Region
rgn.MakeEmpty()
Dim rc As Rectangle = New Rectangle(0, 0, 0, 0)
Dim inimage As Boolean = False
Dim x As Integer
Dim y As Integer
For y = 0 To _img.Height - 1
For x = 0 To _img.Width - 1
If Not (inimage) Then
If _
Not color.op_Equality(_img.GetPixel(x, y), _matchColor)
_
Then
inimage = True
rc.X = x
rc.Y = y
rc.Height = 1
End If
Else
inimage = False
rc.Width = _img.Width - rc.X
rgn.Union(rc)
End If
Next
If inimage Then
inimage = False
rc.Width = _img.Width - rc.X
rgn.Union(rc)
End If
Next
Return rgn
End Function
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #26

P: n/a
"Geoff Jones" <no********@email.com> schrieb:
Many thanks Herfried, I will try your code (but first I'll try and
understand it - we live and learn eh?)


Feel free to ask if something is not clear.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #27

P: n/a
Geoff,

You got from me very early a sample, that combined with the sample on MSDN
and that combined with the code Peter was providing you is in my opinion
more than you got now at least from Herfried.

See this thread at a certain moment you are only answering Herfried. Not
Peter, not Zhang, not me.

Therefore spending time for you is a little bit out of sense at least for
me.

Cor
"Geoff Jones" <no********@email.com>
Hi Cor

I'm afraid I don't know what I've done to upset you. I haven't been
ignoring you! I don't mean to be rude but sometimes I don't fully
understand what you are trying to explain to me. Is it possible that you
are also misunderstanding what I am asking.

I'm sorry again and if you re-read any of my posts you will see that I
have not written anything in a rude manner or indeed ignored you!

Geoff

"Cor Ligthert" <no************@planet.nl> wrote in message
news:OV**************@TK2MSFTNGP15.phx.gbl...
Geoff
Yes, that's right.


I don't know what I did that you ignore me in this way, however when you
don't want my help than be so polite to answer that in an answer to me.

I will try to remember this in future and not bother you anymore.

Cor


Nov 21 '05 #28

P: n/a
Cor

Well, again I apologise but to "ignore" you was not intentional. As you can
see, the thread is large with branches in many areas. It also takes me a
long time to read through the code and understand what is going on.

Sadly it appears that even my earlier apology for not thanking you for the
code you sent has not been accepted. I have, in an earlier post, stated
"With your, and others help (ta Peter), it now works :)" BUT I shall now
thank, including yourself, for all your help in this matter. I'm very
grateful for the help I get on the steep learning code of learning VB.NET,
so again many thanks to:

Cor
Peter
Zhang
Herfried

and anybody else that takes up valueable time to help.

Geoff

"Cor Ligthert" <no************@planet.nl> wrote in message
news:ez*************@TK2MSFTNGP12.phx.gbl...
Geoff,

You got from me very early a sample, that combined with the sample on MSDN
and that combined with the code Peter was providing you is in my opinion
more than you got now at least from Herfried.

See this thread at a certain moment you are only answering Herfried. Not
Peter, not Zhang, not me.

Therefore spending time for you is a little bit out of sense at least for
me.

Cor
"Geoff Jones" <no********@email.com>
Hi Cor

I'm afraid I don't know what I've done to upset you. I haven't been
ignoring you! I don't mean to be rude but sometimes I don't fully
understand what you are trying to explain to me. Is it possible that you
are also misunderstanding what I am asking.

I'm sorry again and if you re-read any of my posts you will see that I
have not written anything in a rude manner or indeed ignored you!

Geoff

"Cor Ligthert" <no************@planet.nl> wrote in message
news:OV**************@TK2MSFTNGP15.phx.gbl...
Geoff

Yes, that's right.

I don't know what I did that you ignore me in this way, however when you
don't want my help than be so polite to answer that in an answer to me.

I will try to remember this in future and not bother you anymore.

Cor



Nov 21 '05 #29

P: n/a
Hi Herfried

Many thanks for the code Herfried. I've managed to get the application
working as I expected. The code did the trick.

Many thanks for your help.

Geoff
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:eN**************@TK2MSFTNGP09.phx.gbl...
"Geoff Jones" <no********@email.com> schrieb:
Many thanks Herfried, I will try your code (but first I'll try and
understand it - we live and learn eh?)


Feel free to ask if something is not clear.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #30

P: n/a
For WindowsXP and Windows 2000 Go to the Control Panel and change the
Settings(to less than 32). Only then it will work.I assume that you have
set the FormTransparency Key property.

with regards,
J.V.Ravichandran
- http://www.geocities.com/
jvravichandran
- http://www.411asp.net/func/search?
qry=Ravichandran+J.V.&cob=aspnetpro
- http://www.southasianoutlook.com
- http://www.MSDNAA.Net
- http://www.csharphelp.com
- http://www.poetry.com/Publications/
display.asp?ID=P3966388&BN=999&PN=2
- Or, just search on "J.V.Ravichandran"
at http://www.Google.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #31

P: n/a
Thank you Ravichandran. It does indeed work if you set the colour depth to,
for example, 16. However, as you'll see in the other posts there is a
"better" way using regions. Several users have kindly given code which shows
how this can be done.

Geoff

"Ravichandran J.V." <jv************@yahoo.com> wrote in message
news:O4**************@TK2MSFTNGP12.phx.gbl...
For WindowsXP and Windows 2000 Go to the Control Panel and change the
Settings(to less than 32). Only then it will work.I assume that you have
set the FormTransparency Key property.

with regards,
J.V.Ravichandran
- http://www.geocities.com/
jvravichandran
- http://www.411asp.net/func/search?
qry=Ravichandran+J.V.&cob=aspnetpro
- http://www.southasianoutlook.com
- http://www.MSDNAA.Net
- http://www.csharphelp.com
- http://www.poetry.com/Publications/
display.asp?ID=P3966388&BN=999&PN=2
- Or, just search on "J.V.Ravichandran"
at http://www.Google.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 21 '05 #32

P: n/a
Geoff,
It has nothing to do with "thank you",

You did not tell why the approaches we offered you did not fit.

While Peter's last message was in my opinion directly a correct one, did you
directly go on with communicating with Herfried when he came in this thread
and left us alone and even not react on the sample from Peter. At the end
you got an answer from Herfried basicly the same as Peters.

When you had answered me directly on my question "if you had tried my
sample", than I had as well directly told to take the approach of MSDN
sample, combined with mine, and in that the part of Peter.

However next time I will leave you for Herfried to answer your questions,
than this will not happen again. Our answers seem not good enough for you.

In addition, that has nothing to do with thank you.

Cor

Nov 21 '05 #33

P: n/a
Cor

I've looked through the tree again and accept what you are saying. I didn't
reply to Peter or yourself and for that I can only apologise. No excuse!
But, as I have so obviously offended you I'll try not to write to this
newsgroup again.

Geoff

"Cor Ligthert" <no************@planet.nl> wrote in message
news:eq**************@TK2MSFTNGP12.phx.gbl...
Geoff,
It has nothing to do with "thank you",

You did not tell why the approaches we offered you did not fit.

While Peter's last message was in my opinion directly a correct one, did
you directly go on with communicating with Herfried when he came in this
thread and left us alone and even not react on the sample from Peter. At
the end you got an answer from Herfried basicly the same as Peters.

When you had answered me directly on my question "if you had tried my
sample", than I had as well directly told to take the approach of MSDN
sample, combined with mine, and in that the part of Peter.

However next time I will leave you for Herfried to answer your questions,
than this will not happen again. Our answers seem not good enough for you.

In addition, that has nothing to do with thank you.

Cor

Nov 21 '05 #34

P: n/a
Geoff,

I am glad that you understand what I was writting, so I forget it and answer
your following questions again normally, I only wanted to show you that this
is not nice for people who wants to help.

Cor
Nov 21 '05 #35

P: n/a
"Ravichandran J.V." <jv************@yahoo.com> schrieb:
For WindowsXP and Windows 2000 Go to the Control Panel and change the
Settings(to less than 32). Only then it will work.I assume that you have
set the FormTransparency Key property.


There are thousands of users who don't run their machine with the required
color depth, so using 'TransparencyKey' for arbitrary shaped forms is not a
good idea.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #36

P: n/a
"Cor Ligthert" <no************@planet.nl> schrieb:
You got from me very early a sample, that combined with the sample on MSDN
and that combined with the code Peter was providing you is in my opinion
more than you got now at least from Herfried.


Your sample doesn't show how to create an arbitrary shaped form from a
bitmap/mask.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #37

P: n/a
"Geoff Jones" <no********@email.com> schrieb:
But, as I have so obviously offended you I'll try not to write to this
newsgroup again.


You are welcome.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #38

P: n/a
You got from me very early a sample, that combined with the sample on
MSDN
and that combined with the code Peter was providing you is in my opinion
more than you got now at least from Herfried.


Your sample doesn't show how to create an arbitrary shaped form from a
bitmap/mask.


Did I say that?

Cor
Nov 21 '05 #39

P: n/a
"Cor Ligthert" <no************@planet.nl> schrieb:
You got from me very early a sample, that combined with the sample on
MSDN
and that combined with the code Peter was providing you is in my opinion
more than you got now at least from Herfried.


Your sample doesn't show how to create an arbitrary shaped form from a
bitmap/mask.


Did I say that?


Well, that's what the OP was obviously looking for.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #40

P: n/a
>>>> You got from me very early a sample, that combined with the sample on
MSDN
and that combined with the code Peter was providing you is in my
opinion more than you got now at least from Herfried.

Your sample doesn't show how to create an arbitrary shaped form from a
bitmap/mask.


Did I say that?


Well, that's what the OP was obviously looking for.

Because it is posible to make a region direct as any shape, there is no need
to use a bitmap as an intermidiate. However because there could be a slight
reason, it was needed to ask from the OP how and why he was using that
bitmap. But you did not. I would have done.

This is the same as when people ask you on Internet where is Salzburg and
than tell them (from your position) to go to the west, without asking what
is there starting point.

Cor
Nov 21 '05 #41

This discussion thread is closed

Replies have been disabled for this discussion.