Hi,
I have posted twice regarding this issue, butI still haven't seen a nice approach, so I have to ask help for this because I want to believe that it is possible, I'm using this source found inCodeProject.combut it is designed to be usedwith panel insteadof forms andI just can't make it work, but if it can be used with panels, why can't be used with mdichilds?, at the end it is just a drawn rectangle, can some one help meto adapt it to forms ?, I'm sure there are lots of people looking for this:
Thanks in advance
Imports System
Imports System.Text
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
Imports System.Collections.Generic
Public Class ShadowPanelasas
Inherits Windows.Forms.Form
Private _panelColor As Color
Public Property PanelColor() As Color
Get
Return _panelColor
End Get
Set(ByVal value As Color)
_panelColor = value
End Set
End Property
Private _borderColor As Color
Public Property BorderColor() As Color
Get
Return _borderColor
End Get
Set(ByVal value As Color)
_borderColor = value
End Set
End Property
Private shadowSize As Integer = 5
Private shadowMargin As Integer = 2
' static for good perfomance
Shared shadowDownRight As Image = New Bitmap(GetType(ShadowPanel), "tshadowdownright.png")
Shared shadowDownLeft As Image = New Bitmap(GetType(ShadowPanel), "tshadowdownleft.png")
Shared shadowDown As Image = New Bitmap(GetType(ShadowPanel), "tshadowdown.png")
Shared shadowRight As Image = New Bitmap(GetType(ShadowPanel), "tshadowright.png")
Shared shadowTopRight As Image = New Bitmap(GetType(ShadowPanel), "tshadowtopright.png")
Public Sub New()
End Sub
Protected Overloads Overrides Sub OnPaint(ByVal e As PaintEventArgs)
MyBase.OnPaint(e)
' Get the graphics object. We need something to draw with ;-)
Dim g As Graphics = e.Graphics
' Create tiled brushes for the shadow on the right and at the bottom.
Dim shadowRightBrush As New TextureBrush(shadowRight, WrapMode.Tile)
Dim shadowDownBrush As New TextureBrush(shadowDown, WrapMode.Tile)
' Translate (move) the brushes so the top or left of the image matches the top or left of the
' area where it's drawed. If you don't understand why this is necessary, comment it out.
' Hint: The tiling would start at 0,0 of the control, so the shadows will be offset a little.
shadowDownBrush.TranslateTransform(0, Height - shadowSize)
shadowRightBrush.TranslateTransform(Width - shadowSize, 0)
' Define the rectangles that will be filled with the brush.
' (where the shadow is drawn)
' X
' Y
' width (stretches)
' height
Dim shadowDownRectangle As New Rectangle(shadowSize + shadowMargin, Height - shadowSize, _
Width - (shadowSize * 2 + shadowMargin), shadowSize)
' X
' Y
' width
' height (stretches)
Dim shadowRightRectangle As New Rectangle(Width - shadowSize, shadowSize + shadowMargin, _
shadowSize, Height - (shadowSize * 2 + shadowMargin))
' And draw the shadow on the right and at the bottom.
g.FillRectangle(shadowDownBrush, shadowDownRectangle)
g.FillRectangle(shadowRightBrush, shadowRightRectangle)
' Now for the corners, draw the 3 5x5 pixel images.
g.DrawImage(shadowTopRight, New Rectangle(Width - shadowSize, _
shadowMargin, shadowSize, shadowSize))
g.DrawImage(shadowDownRight, New Rectangle(Width - shadowSize, _
Height - shadowSize, shadowSize, shadowSize))
g.DrawImage(shadowDownLeft, New Rectangle(shadowMargin, _
Height - shadowSize, shadowSize, shadowSize))
' Fill the area inside with the color in the PanelColor property.
' 1 pixel is added to everything to make the rectangle smaller.
' This is because the 1 pixel border is actually drawn outside the rectangle.
' X
' Y
' Width
' Height
Dim fullRectangle As New Rectangle(1, 1, Width - (shadowSize + 2), Height - (shadowSize + 2))
If Not PanelColor = Nothing Then
Dim bgBrush As New SolidBrush(_panelColor)
g.FillRectangle(bgBrush, fullRectangle)
End If
' Draw a nice 1 pixel border it a BorderColor is specified
If Not BorderColor = Nothing Then
Dim borderPen As New Pen(BorderColor)
g.DrawRectangle(borderPen, fullRectangle)
End If
' Memory efficiency
shadowDownBrush.Dispose()
shadowRightBrush.Dispose()
shadowDownBrush = Nothing
shadowRightBrush = Nothing
End Sub
' Correct resizing
Protected Overloads Overrides Sub OnResize(ByVal e As EventArgs)
MyBase.Invalidate()
MyBase.OnResize(e)
End Sub
End Class