V
vikasmaderna
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
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