|
|
|
start date: Wed, 01 Aug 2007 06:09:36 -0700,
posted on: microsoft.public.dotnet.framework.compactframework
back
| Thread Index |
|
1
unknown
|
|
2
Arun
|
|
3
vikas maderna
|
|
4
Mark Arteaga online_marteaga_@_opennetcf-com
|
Transparent Picturebox in VB.net 2005
Hi,
I have read the samples of transparent Picturebox, but i was not able
to get it working could anyone help me in solving the problem
****************************** Class code for Transparent PicBox
*************
Imports System.Drawing.Imaging
Imports System.Drawing.Imaging.ImageAttributes
Public Class PictureboxEX
Inherits System.Windows.Forms.PictureBox
Protected Overrides Sub OnPaint(ByVal e As
System.Windows.Forms.PaintEventArgs)
Dim attr As Imaging.ImageAttributes = New
Imaging.ImageAttributes()
attr.SetColorKey(Color.Transparent, Color.Transparent)
' attr.SetColorKey(Color.FromArgb(255, 0, 255),
Color.FromArgb(255, 0, 255))
e.Graphics.DrawImage(Me.Image, Me.ClientRectangle, 0, 0,
Me.Image.Width, Me.Image.Height, GraphicsUnit.Pixel, attr)
End Sub
Protected Overloads Overrides Sub OnPaintBackground(ByVal e As
System.Windows.Forms.PaintEventArgs)
Dim sb As New SolidBrush(Parent.BackColor)
e.Graphics.FillRectangle(sb, Me.ClientRectangle)
End Sub
End Class
************************** Form Code *********************
Public Class Form1
Protected WithEvents pb As PictureboxEX = New PictureboxEX
Dim x, y As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
' Dim pb1 As New PictureboxEX
Dim pb As PictureboxEX = New PictureboxEX
pb.Image = Image.FromFile("C:\gif1.gif")
pb.Location = New System.Drawing.Point(x, 0)
x += 50
' pb.Size = New System.Drawing.Size(240, 240)
Me.PictureBox1.Location = New System.Drawing.Point(56, 88)
Me.Picturebox1.Controls.Add(pb)
End Sub
End Class
***************************************
but when we use the code, we are not getting the true transparency, if
we want to see through the pictureboxes we cant, the black color of
is coming instead of form.
thanks & regards
vikas
Date:Wed, 01 Aug 2007 06:09:36 -0700
Author:
|
Re: Transparent Picturebox in VB.net 2005
This is in C#
Your SetColorKey need some changes,
try this
Bitmap bmp = new Bitmap(base.Image);
attr.SetColorKey(bmp.GetPixel(0, 0), bmp.GetPixel(0, 0))
Please let me know if this solved your issue.
On Aug 1, 6:09 am, vikasmade...@gmail.com wrote:
> Hi,
>
> I have read the samples of transparent Picturebox, but i was not able
> to get it working could anyone help me in solving the problem
>
> ****************************** Class code for Transparent PicBox
> *************
>
> Imports System.Drawing.Imaging
>
> Imports System.Drawing.Imaging.ImageAttributes
>
> Public Class PictureboxEX
>
> Inherits System.Windows.Forms.PictureBox
>
> Protected Overrides Sub OnPaint(ByVal e As
> System.Windows.Forms.PaintEventArgs)
>
> Dim attr As Imaging.ImageAttributes = New
> Imaging.ImageAttributes()
> attr.SetColorKey(Color.Transparent, Color.Transparent)
> ' attr.SetColorKey(Color.FromArgb(255, 0, 255),
> Color.FromArgb(255, 0, 255))
> e.Graphics.DrawImage(Me.Image, Me.ClientRectangle, 0, 0,
> Me.Image.Width, Me.Image.Height, GraphicsUnit.Pixel, attr)
> End Sub
> Protected Overloads Overrides Sub OnPaintBackground(ByVal e As
> System.Windows.Forms.PaintEventArgs)
> Dim sb As New SolidBrush(Parent.BackColor)
> e.Graphics.FillRectangle(sb, Me.ClientRectangle)
>
> End Sub
>
> End Class
>
> ************************** Form Code *********************
>
> Public Class Form1
> Protected WithEvents pb As PictureboxEX = New PictureboxEX
> Dim x, y As Integer
> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
> As System.EventArgs) Handles Button1.Click
> ' Dim pb1 As New PictureboxEX
> Dim pb As PictureboxEX = New PictureboxEX
>
> pb.Image = Image.FromFile("C:\gif1.gif")
>
> pb.Location = New System.Drawing.Point(x, 0)
> x += 50
> ' pb.Size = New System.Drawing.Size(240, 240)
>
> Me.PictureBox1.Location = New System.Drawing.Point(56, 88)
> Me.Picturebox1.Controls.Add(pb)
>
> End Sub
> End Class
> ***************************************
>
> but when we use the code, we are not getting the true transparency, if
> we want to see through the pictureboxes we cant, the black color of
> is coming instead of form.
>
> thanks & regards
>
> vikas
Date:Fri, 03 Aug 2007 15:09:02 -0700
Author:
|
Re: Transparent Picturebox in VB.net 2005
Hi Arun,
Sorry i didnt work, still the black background is coming behind the
image.
thanks for posting.
*** Sent via Developersdex http://www.developersdex.com ***
Date:Sun, 05 Aug 2007 11:44:27 -0700
Author:
|
Re: Transparent Picturebox in VB.net 2005
Override OnPaintBackground() and do nothing in it. That should work.
--
Mark Arteaga
Principal Partner
OpenNETCF Consulting
http://www.opennetcf.com | http://blog.markarteaga.com
> Hi Arun,
>
> Sorry i didnt work, still the black background is coming behind the
> image.
>
> thanks for posting.
>
> *** Sent via Developersdex http://www.developersdex.com ***
>
Date:Wed, 8 Aug 2007 13:53:09 +0000 (UTC)
Author:
|
|
|