elvinguitar
elvinguitar

Reputation: 149

Make the form's background to transparent

I made a borderless form and I set my background image (in PNG format) to something like the one shown in the image below. What I want is to make the form's background transparent so that only the circular image is shown. I tried changing the form's BackColor to Transparent but I'm getting an error saying Property value is not vald

image

Upvotes: 2

Views: 45706

Answers (6)

KRIPS
KRIPS

Reputation: 64

You can try like, set form's properties from designing side

back color=system>active-caption and set transparency >active-caption

and write following code in to the form constructor or activated event:

 SetStyle(ControlStyles.SupportsTransparentBackColor, True)
 Me.BackColor = Color.Transparent

You can also this video : https://www.youtube.com/watch?v=CEuxm-FV-cU

Upvotes: 0

user5019346
user5019346

Reputation: 1

Label1.BackgroundColor = color.FromArgb(25, color.blue)

Upvotes: 0

Manik G
Manik G

Reputation: 341

   Public Class Form1
Private _InitialStyle As Integer
<Runtime.InteropServices.StructLayout(Runtime.InteropServices.LayoutKind.Sequential)> Public Structure MARGINS
    Public LeftWidth As Integer
    Public RightWidth As Integer
    Public TopHeight As Integer
    Public Buttomheight As Integer
End Structure

<Runtime.InteropServices.DllImport("dwmapi.dll")>
Public Shared Function DwmExtendFrameIntoClientArea(ByVal hWnd As IntPtr, ByRef pMarinset As MARGINS) As Integer
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
   'TODO: This line of code loads data into the 'DataSet1.MainMenuMaster' table. 'You can move, or remove it, as needed.
   Try
        Me.BackColor = Color.DarkBlue
        Dim margins As MARGINS = New MARGINS
        margins.LeftWidth = -1
        margins.RightWidth = -1
        margins.TopHeight = -1
        margins.Buttomheight = -1
        Dim result As Integer = DwmExtendFrameIntoClientArea(Me.Handle, margins)
    Catch ex As Exception
        Application.Exit()
    End Try
End Sub

End Class

Upvotes: 1

Manik G
Manik G

Reputation: 341

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

         Me.TransparencyKey = Color.LightBlue
         Me.BackColor = Color.LightBlue

    End Sub

Upvotes: 10

Vignesh Kumar A
Vignesh Kumar A

Reputation: 28413

Try this

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Me.BackColor = Color.Transparent
End Sub

(or)

Call the SetStyle method of your form in the constructor.

SetStyle(ControlStyles.SupportsTransparentBackColor, True)

Upvotes: 1

aksu
aksu

Reputation: 5235

If the background color to transparent work, you could set TransparencyKey attribute to yur form to make the white color transparent.

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Me.TransparencyKey = Color.White 'if this doesn't work you try:
   'Me.TransparencyKey = Me.BackColor
End Sub

Upvotes: 3

Related Questions