vb.netflowlayoutpanel

Making A FlowLayoutPanel have a transparent background


I have a button that dynamically adds up to 24 labels to the form. The problem is their location.

I figured out that instead of manually setting a specific location for each, I can have them automatically arranged like a FlowLayoutPanel does. But the FLP will be on top and hide controls under it. And sending it to back is worse. So i want to bring it to front but keep it transparent, so that it doesn't hide the other controls under it.

Any suggestions will be great

Thanks.


Solution

  • I can have them automatically arranged like a FlowLayoutPanel does. But I can't use one because it will be on top and hide the images in my pic's.

    Well, you can use a FlowLayoutPanel with a transparent background so it doesn't hide the other controls you have. How to do that? Well, this answer shows you how to make a transparent Panel. You should be able to easily adjust it to work with a FlowLayoutPanel using something like this:

    Public Class TransparentFLP
        Inherits FlowLayoutPanel
    
        Protected Overrides ReadOnly Property CreateParams() As System.Windows.Forms.CreateParams
            Get
                Dim cp As CreateParams = MyBase.CreateParams
                cp.ExStyle = cp.ExStyle Or &H20 ''#WS_EX_TRANSPARENT
                Return cp
            End Get
        End Property
        Protected Overrides Sub OnPaintBackground(ByVal e As System.Windows.Forms.PaintEventArgs)
            ''#MyBase.OnPaintBackground(e) --> Don't uncomment this orelse
                                              'it will cause the BackColor to be redrawn.
        End Sub
    
    End Class
    

    P.S. I'm not sure about the use of your 4 panels, but you might consider using a TableLayoutPanel instead.

    Hope that helps :)