Transparent Background

PwUP

Member
Joined
Sep 21, 2009
Messages
23
Programming Experience
1-3
Hi.
I have a class which draws stuff like lines, rectangles ad images in a form.
But it also draw a background rectangle before other things. How may i disable it?
(I've taken a screenshot to show you better what i mean:
proj.png

When i create my second class it draws a gray rectangle, as well as the blue one ,which doesen't allow me to see what's going on with the below class.I want to make it transparent.)
 
Use the SetStyle Method in the constructor to set Transparent-Background to True.

VB.NET:
Public Sub New()
      MyBase.New()
      Me.SetStyle(TransparentBackgroundEnumThingieGoesHere, True)
      Me.Background = Color.Transparent
End Sub

Bobby
 
Thanks, but nothing changes :mad:
I don't really understand why..
This is my class code
VB.NET:
Public Class drawer
    Inherits Control
    Dim steps As Integer = 0


    Private Sub drawer_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        e.Graphics.DrawLine(Pens.Red, 0, 0, 100, 100)
    End Sub

    Public Sub New()
        MyBase.New()
        Me.SetStyle(ControlStyles.SupportsTransparentBackColor, True)
        Me.BackColor = Color.Transparent
    End Sub
End Class
I read now that supportstransparentbackcolor wants alos userpaint to be true, so i put this:
VB.NET:
        Me.SetStyle(ControlStyles.UserPaint, True)
        Me.SetStyle(ControlStyles.SupportsTransparentBackColor, True)
        Me.BackColor = Color.Transparent
but it still doesen't work..
 
Last edited:
Perhaps you could try inheriting from UserControl instead of Control. If I remember correctly, you can set a UserControl's BackColor to Color.Transparent -- no need to bother about SetStyles.

cheers, VicJ
 
It doesen't work. I'm thinking about making only one class and use there every other classes' draw actions. :(
Anyway thank you and Robert_Zenz
 
I assure you that a User.Control with BackColor=Color.Transparent will show up with the required transparency when you run the program. The picture you showed is clearly from the forms Designer. The Designer does not show control transparency.

Your plan to do all the drawing in one class is probably a better design anyway. Why use a separate control (or usercontrol), if its only purpose is to draw one thing on top of another? You can draw a whole series of things one after another in a form's Paint event handler, for example.

regards, Vic
 
Back
Top