I have been trying to make a picturebox transparent. But even though
there is no graphics file in it yet, it still shows up as white. I am
using this code on a newly created picturebox:
me.PictureBox6.BackColor = system.Drawing.Color.Transparent
Why wouldn't that make my picturebox the same color as the panel or
background image? (I've tried both popping it over an image, and
another picturebox.)
Please help!
Thanks
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
ImageAttributes attr = new ImageAttributes();
attr.SetColorKey(Color.FromArgb(255, 0, 255), Color.FromArgb(255, 0, 255));
e.Graphics.DrawImage(this.Image, this.ClientRectangle, 0, 0,
this.Image.Width, this.Image.Height, GraphicsUnit.Pixel, attr);
}
The color 255, 0, 255 (RGB) is a transparent.
Best regards,
Sergey Bogdanov
There are also a number of online converters...
Cheers
Daniel
--
http://www.danielmoth.com/Blog/
"BlarneyFOR" <crumb...@yahoo.com> wrote in message
news:1105128013.0...@f14g2000cwb.googlegroups.com...
"BlarneyFOR" <crumb...@yahoo.com> wrote in message
news:1105124861....@z14g2000cwz.googlegroups.com...
> Sure! It could be easy translated to VB.NET.
>
> Best regards,
> Sergey Bogdanov
>
Thanks, I found an online converter. One more question. Where do I put
the code and call it? Sorry...I am just not clear what I am doing here.
--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
> Check this out if you don't have a book:
> http://www.harding.edu/USER/fmccown/WWW/vbnet_csharp_comparison.html
>
> There are also a number of online converters...
>
> Cheers
> Daniel
> --
> http://www.danielmoth.com/Blog/
>
Thanks for the link (bookmarked). I found a coverter here:
http://www.ragingsmurf.com/vbcsharpconverter.aspx
just not sure where to place the code now. <blush>
Dim pb As PictureBoxEx = New PictureBoxEx()
...
' Your form constructor code
pb.Location = New System.Drawing.Point(0, 0)
pb.Size = New System.Drawing.Size(240, 240)
...
Controls.Add(pb);
Hope this help,
Sergey Bogdanov
'My Form1 code (form1 is where I'd want the transparent picturebox):
Imports transparency.PictureboxEX.ControlCollection
Public Class Form1
Inherits System.Windows.Forms.Form
Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
MyBase.Dispose(disposing)
End Sub
'NOTE: The following procedure is required by the Windows Form
Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Private Sub InitializeComponent()
Me.PictureBox1 = New System.Windows.Forms.PictureBox
'
'PictureBox1
'
Dim pb As PictureboxEX = New PictureboxEX
pb.Location = New System.Drawing.Point(0, 0)
pb.Size = New System.Drawing.Size(240, 240)
Me.PictureBox1.Location = New System.Drawing.Point(56, 88)
Me.Picturebox1.Controls.Add(pb)
'
'Form1
'
Me.ClientSize = New System.Drawing.Size(242, 272)
Me.Controls.Add(Me.PictureBox1)
Me.Text = "Form1"
End Sub
'My PictureboxEX class code:
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.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
End Class
Public Class Form1
Inherits System.Windows.Forms.Form
Protected WithEvents pb As PictureboxEX = New PictureboxEX
...
Private Sub InitializeComponent()
pb.Location = New System.Drawing.Point(0, pb.Size = New
System.Drawing.Size(240, 240)
pb.Image = New
Bitmap(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("YOUAPPLICATIONNAME.Bitmap1.bmp"))
Me.Controls.Add(pb)
...
Best regards,
Sergey Bogdanov
> You forgot to include Image to your picture box - include your .bmp file
> into the solution and set property "Build Action" to Embedded
> Resource. Also I have found some errors:
>
> Public Class Form1
> Inherits System.Windows.Forms.Form
> Protected WithEvents pb As PictureboxEX = New PictureboxEX
>
> ...
>
> Private Sub InitializeComponent()
> pb.Location = New System.Drawing.Point(0, pb.Size = New
> System.Drawing.Size(240, 240)
> pb.Image = New
> Bitmap(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("YOUAPPLICATIONNAME.Bitmap1.bmp"))
> Me.Controls.Add(pb)
> ...
>
>
> Best regards,
> Sergey Bogdanov
Thank you Sergey! It worked! In fact it worked so well my embedded image
is transparent all the way down to the today screen... I figure I'll be
able to tweak it so that it doesn't show through the project.
thanks again!
protected override void
OnPaintBackground(System.Windows.Forms.PaintEventArgs e)
{
SolidBrush sb = new SolidBrush(Parent.BackColor);
e.Graphics.FillRectangle(sb, this.ClientRectangle);
}
Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com