VB.Net - Semi Transparent Panel

This snippet shows how to develop a custom panel which is semi transparent by overriding CreateParams and the OnPaint method of the Panel control.

xPanel

  1. Imports System.Windows.Forms  
  2.  
  3. Public Class xPanel  
  4.     Inherits Panel  
  5.  
  6.     Protected Overrides ReadOnly Property CreateParams() As System.Windows.Forms.CreateParams  
  7.         Get  
  8.             Dim cp As CreateParams  
  9.             cp = MyBase.CreateParams  
  10.             cp.ExStyle = &H20  
  11.             Return cp  
  12.         End Get  
  13.     End Property  
  14.  
  15.     Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)  
  16.         e.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(128, 0, 0, 0)), Me.ClientRectangle)  
  17.     End Sub  
  18.  
  19.     Protected Overrides Sub OnSizeChanged(ByVal e As System.EventArgs)  
  20.         MyBase.OnSizeChanged(e)  
  21.     End Sub  
  22. End Class 

1 comment:

Unknown said...

This code example gives me the desired transparency affect that I am looking for, but when I try and move the control around the screen, the panel seems to disappear. Is there any way around this issue?

Post a Comment