In VS 2003 it is really easy to add the VbPowerPack and use BlendPanels to achieve gradients. However, BlendPanels are somewhat buggy when it comes to Docking and form Opacity. Am I correct in assuming that manually coding gradients on a form will not affect the forms ability to adjust in degrees of Opacity? This question is in regards to a project that I am working on in VS 2005.
Show the love! Click (rate this post) under my name if I was helpful.
No thoughts? Anyway, I've created a sub that handles the gradient for each of the panels on a form. However, If there are other controls on the panel (Like labels) with a transparent background then they do not reflect the gradient. Can you see where I went wrong?
Code:
Private Sub uiMainForm_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) _
Handles Me.Paint, BlendPanel1.Paint
' FILL BLENDPANEL1 GRADIENT
FillLinearGradient(Me.BlendPanel1, 0, 0, Me.BlendPanel1.Width, Me.BlendPanel1.Height, _
Color.FromKnownColor(KnownColor.Control), Color.FromKnownColor(KnownColor.ControlDark), LinearGradientMode.Vertical)
End Sub
Private Sub FillLinearGradient(ByRef sender As Panel, ByVal leftPos As Integer, ByVal topPos As Integer, _
ByVal recWidth As Integer, ByVal recHeight As Integer, ByVal color1 As Color, _
ByVal color2 As Color, ByVal direction As LinearGradientMode)
Dim brushSize As New Rectangle(leftPos, topPos, recWidth, recHeight)
Dim myGraphics As Graphics
Dim myLinGradBrush As New LinearGradientBrush(brushSize, color1, color2, direction)
Dim myBrush As Brush = myLinGradBrush
' SET WRAPMODE FOR LINEARGRADIENTBRUSH NOT CLAMP
myLinGradBrush.WrapMode = WrapMode.Tile
' DRAW GRADIENT
myGraphics = sender.CreateGraphics()
' FILL THE RECTANGLE
myGraphics.FillRectangle(myBrush, leftPos, topPos, recWidth, recHeight)
End Sub
Show the love! Click (rate this post) under my name if I was helpful.
Shardox, yours works in Horizontal mode, but not Vertical. I'm not sure why that is but I need it in Vertical. Also, why do labels show the correct background with yours and not mine?
Show the love! Click (rate this post) under my name if I was helpful.
Ok, I figured out why it doesn't work in Vertical and that is because you are using the entire ClientRectangle. I am sending it controls or objects that are relatively small, so I got around this by adding parameters to your Sub and passing the height and width of the sending object. I still do not understand why the labels perform differently though.
Show the love! Click (rate this post) under my name if I was helpful.
Ok, I've got all the kinks worked out of the gradient now. But I am still not able to make a form Opaque. I have tried hard coding the opacity as well as setting the form property, but to no avail. Can anyone shed some light on this?
Last edited by circuits2; Nov 16th, 2006 at 03:18 PM.
Show the love! Click (rate this post) under my name if I was helpful.
In VS 2003 it is really easy to add the VbPowerPack and use BlendPanels to achieve gradients. However, BlendPanels are somewhat buggy when it comes to Docking and form Opacity. Am I correct in assuming that manually coding gradients on a form will not affect the forms ability to adjust in degrees of Opacity? This question is in regards to a project that I am working on in VS 2005.
Hi,
You could use the opacity Mask to make it gradient, here's the link;
The opacity mask in that link is for images. Not really relevant for what I'm doing. All I want to achieve is fading a form in and out. I don't know why it is all of a sudden so complicated.
Show the love! Click (rate this post) under my name if I was helpful.
not sure where you are getting held up circuits.. here is a screen shot of a form being painted with a horizontal linear gradient brush, that has a label on it (back color set to transparent) and opacity set (at design time) to 50%
The MDI child form you create in this step is a standard Windows Form. As such, it has an Opacity property, which enables you to control the transparency of the form. However, the Opacity property was designed for top-level windows. Do not use it with MDI child forms, as painting problems can occur.
That explains it! Thanks for finding that! What is a good transitional technique for MDI Children? The screen flash when closing and opening, then docking forms annoys me to no end. I tried the suspend layout technique but that still doesn't quite do it for me. I would like to implement something impressive. Thanks.
Show the love! Click (rate this post) under my name if I was helpful.
maybe you could have 1 form that is docked, and is basically a container, and use the form in a form method to display whatever docked child forms you need.
Or you could try a rollout form method.. where you use a loop/timer to shrink the form down to 0,0 in size and then roll out the new one.
I guess it depends on how fancy you want to get. Maybe other members will have some other suggestions too??
I think I might try a variation of the rollout method. If I get it to work like I want it to then I will post the code. I'm still open to suggestion if anyone has any other ideas. Thanks for clearing this up for me Klein.
Show the love! Click (rate this post) under my name if I was helpful.