none
How to make a semi-transparent panel?

    Question

  • Hi,

    I want to make a panel semi-transparent. It has controls in it, which need to be fully visible, but the panel should be partly transparent to give a glass effect. How do I do this?

    I've only started learning OO in VB.NET.

    Thanks,

    Rahul

    Thursday, January 31, 2013 6:33 AM

Answers

All replies

  • The commented out code was for something else I was doing with a picturebox.

    'Imports System.Drawing.Drawing2D
    
    Public Class Form1
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
            'Dim bm As Bitmap = Image.FromFile("C:/Users/John/Desktop/Picture Files/Crossbones BMP.Bmp")
            'Dim bt As New Bitmap(bm.Width, bm.Height)
            ' Dim g As Graphics = Graphics.FromImage(bt)
            'Dim gp As New GraphicsPath()
            'gp.AddEllipse(10, 10, bm.Width - 20, bm.Height - 20)
            'g.Clear(Color.Magenta)
            'g.SetClip(gp)
            'g.DrawImage(bm, New Rectangle(0, 0, bm.Width, bm.Height), 0, 0, bm.Width, bm.Height, GraphicsUnit.Pixel)
            'g.Dispose()
            'bt.MakeTransparent(Color.Magenta)
    
            Panel1.BackColor = Color.FromArgb(0, 100, 100, 100)
            
        End Sub
    
    
        Private Sub Panel2_Paint(sender As Object, e As PaintEventArgs) Handles Panel2.Paint
    
        End Sub
    
        Private Sub VScrollBars_Scroll(sender As Object, e As ScrollEventArgs) Handles VScrollBar1.Scroll, VScrollBar2.Scroll, VScrollBar3.Scroll, VScrollBar4.Scroll
            Panel1.BackColor = Color.FromArgb(VScrollBar1.Value, VScrollBar2.Value, VScrollBar3.Value, VScrollBar4.Value)
            Label1.Text = VScrollBar1.Value.ToString
            Label2.Text = VScrollBar2.Value.ToString
            Label3.Text = VScrollBar3.Value.ToString
            Label4.Text = VScrollBar4.Value.ToString
        End Sub
    
        Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click
    
        End Sub
    
        Private Sub Label2_Click(sender As Object, e As EventArgs) Handles Label2.Click
    
        End Sub
    
        Private Sub Label3_Click(sender As Object, e As EventArgs) Handles Label3.Click
    
        End Sub
    
        Private Sub Label4_Click(sender As Object, e As EventArgs) Handles Label4.Click
    
        End Sub
    
        Private Sub Panel1_Paint(sender As Object, e As PaintEventArgs) Handles Panel1.Paint
    
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    
        End Sub
    End Class
    


    You've taught me everything I know but not everything you know.

    Thursday, January 31, 2013 7:08 AM
  • Tips:

    Use BackColor Property

    Resources:

    Semi-Transperent Forms

    semi-transperent Controls

    semi-transparent panels

    Example:

    Control.BackColor=Color.FromArgb(AlphaValue,RedValue,GreenValue,BlueValue)

    'Change the value of Alpha to make it semi transparent


    Do the Impossible

    • Marked as answer by rahuly1039 Friday, February 08, 2013 4:05 PM
    Thursday, January 31, 2013 8:00 AM
  • Using backcolor semi transparency on panels can result in slow redraw times for the whole form. If you notice re-paints are halted or slow - you may consider the following.

    1)Instead of setting backcolor to transparent, use a copyfromscreen function to create a bitmap of the region that will be directly underneath the panel.

    2)Then modify that bitmap using lock-bit method so it is appropriately shaded.

    3)Then set that bitmap as the backgroundimage of the panel.

    4)Then show the panel.

      Note: for step (1) there are other ways to obtain that bitmap - depending on the your graphics methods on the parent form.

    EDIT : PS - I forgot -  for step (2) - no need to use lock-bit method - just use GDI graphics.fillrectangle(suitible transparent brush, bitmap rectangle)   to modify the bitmap.


    Leon C Stanley - - A dinky di VB'er - -


    • Edited by LeonCS Thursday, January 31, 2013 10:43 AM
    Thursday, January 31, 2013 9:36 AM