akrocks
03-04-2006, 10:06 PM
For my own future refrence and your learning pleasure...
Ok, whatever... But I do think this is a safe place to hold my new found know-how, and I'm sure someone will find this useful. I finally figured out how to make a custom control transparent. Well, I guess not transparent, but it works good enough for me.
The experts who hang around here probably already know all I did was set the regions, but the point is: that I figured out how to do I on my own with the exception of lots of researching on finding the right methods.
So anyways, here is how I did it. Let's make a shape using PointF in the Paint Sub!
'Create your canvas, pens, brushes and whatever you will need for your basic drawings.
Dim Canvas As Graphics = Me.CreateGraphics
Dim myBrush As New SolidBrush(System.Drawing.SystemColors.Info)
Dim newFillMode As FillMode = FillMode.Winding
'Now, lets make our shape.
Dim myShape() as PointF = { _
New PointF(8, 8), _
New PointF(12, 4), _
New pointF(16, 8), _
new pointf(16, 12), _
New PointF(12, 16), _
New PointF(8, 12), _
New PointF(8, 8) _
}
'By the way, I just made that shape as I was typing this up... So not really sure what it looks like o_O
'Create a new graphics path (Not really sure if this is nessisary but it keeps our original shape safe)
Dim msPath As New Drawing2D.GraphicsPath
msPath.AddLines(myShape)
'Now we make a region as the path.
Dim Rgn As New Region(msPath)
'And set the control to the new region.
Me.Region = Rgn
'Draw the shape
Canvas.FillPolygon(myBrush, myShape, newFillMode)
'Clean up
Canvas.Dispose()
And there you have it! Mock up Transparent Controls from shapes! Hope this helps you, because it really helped me! Happy control building!
Ok, whatever... But I do think this is a safe place to hold my new found know-how, and I'm sure someone will find this useful. I finally figured out how to make a custom control transparent. Well, I guess not transparent, but it works good enough for me.
The experts who hang around here probably already know all I did was set the regions, but the point is: that I figured out how to do I on my own with the exception of lots of researching on finding the right methods.
So anyways, here is how I did it. Let's make a shape using PointF in the Paint Sub!
'Create your canvas, pens, brushes and whatever you will need for your basic drawings.
Dim Canvas As Graphics = Me.CreateGraphics
Dim myBrush As New SolidBrush(System.Drawing.SystemColors.Info)
Dim newFillMode As FillMode = FillMode.Winding
'Now, lets make our shape.
Dim myShape() as PointF = { _
New PointF(8, 8), _
New PointF(12, 4), _
New pointF(16, 8), _
new pointf(16, 12), _
New PointF(12, 16), _
New PointF(8, 12), _
New PointF(8, 8) _
}
'By the way, I just made that shape as I was typing this up... So not really sure what it looks like o_O
'Create a new graphics path (Not really sure if this is nessisary but it keeps our original shape safe)
Dim msPath As New Drawing2D.GraphicsPath
msPath.AddLines(myShape)
'Now we make a region as the path.
Dim Rgn As New Region(msPath)
'And set the control to the new region.
Me.Region = Rgn
'Draw the shape
Canvas.FillPolygon(myBrush, myShape, newFillMode)
'Clean up
Canvas.Dispose()
And there you have it! Mock up Transparent Controls from shapes! Hope this helps you, because it really helped me! Happy control building!