Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Making a control transparent?

Status
Not open for further replies.

grungekid

Programmer
Jan 22, 2004
6
NL
Hi all,

I am making a usercontrol but i would like it to make its background colour transparent?

Does anyone know how to do this?

i would like the background colour to be transperent when the control is moved as well, so it does not affect other controls on the form

this is my code so far.....

Public Class MyTransparentControl
Inherits UserControl

Protected Overrides Sub OnPaint(ByVal e As Windows.Forms.PaintEventArgs)
Dim myPath As New System.Drawing.Drawing2D.GraphicsPath
Dim myGraphics As Graphics = e.Graphics
Dim myPen As New Pen(Color:=Me.ForeColor, Width:=2)

Me.Size = New Size(100, 100)

myPath.AddLine(0, 0, 100, 0)
myPath.AddLine(100, 0, 100, 100)
myPath.AddLine(100, 100, 0, 100)
myPath.AddLine(0, 100, 0, 0)
myGraphics.DrawPath(Pen:=myPen, path:=myPath)

End Sub

End Class



Dont forget to rock and roll this summer!
 
the problem with the transparent color is that it isn't really transparent it's the background color of the parent.

However you may have noticed that a form has an opacity property wich makes really transparent. So instead of inheriting from the usercontrol. inherit from the form and don't forget to set it's toplevel to false.

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
hi, i have tried this but i seem to get an exception that i don't understand:

An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll

Additional information: Exception has been thrown by the target of an invocation.

however, i dont think this would work correctly because, low opacity will make the form and the control invisible, i still need to see the drawing on the control and not just make the entire thing invisible?

see what i need is a kind of sprite, that has a colour mask, so the you can only see the drawing and not the white background anybody got any clues?


thanks anyway
 
I found this

Controls with a "Transparent" color actually render their parent's background, so you're seeing the White background of the Form, not the PictureBox. Three easy ways to deal with this:


Use a Panel with it's "BackgroundImage" property set instead of a PictureBox, and parent the LinkLabels to the panel (PictureBoxes generally don't have children)
Set the BackgroundImage of the Form to the image (basically the same as 1 above, but avoids the extra control)
In code, set the Parent of the LinkLabel to be the PictureBox. You'll need to update the LinkLabel's position to match the new origin of the parent if the PictureBox isn't at (0,0)
(Shawn Burke on microsoft.public.dotnet.framework.windowsforms newsgroup)

I found it here


Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top