Shadow Windows
Introduction
The ShadowWindow class provided by NetXP can be used to add
custom-drawn drop shadows to any .NET control or form. This section provides
some code snippets for using the ShadowWindow class correctly.
C#
// at the top of source code file:
using NETXP.Library;
using NETXP.Win32;
// inside custom control class:
private ShadowWindow shadowBottom = null;
private ShadowWindow shadowRight = null;
// inside the overridden OnHandleCreated method:
this.shadowRight = new ShadowWindow(Handle);
this.shadowBottom = new ShadowWindow(Handle);
this.shadowRight.ShadowType = ShadowType.Right;
this.shadowBottom.ShadowType = ShadowType.Bottom;
// handle PaintShadow for each shadow window
this.shadowRight.PaintShadow += new PaintEventHandler(OnPaintRightShadow);
this.shadowBottom.PaintShadow += new
PaintEventHandler(OnPaintBottomShadow);
// show the shadow windows
shadowRight.Show();
shadowBottom.Show();
// inside the overridden OnHandleDestroyed method:
if(shadowRight != null)
{
shadowRight.Close();
shadowRight = null;
}
if(shadowBottom != null)
{
shadowBottom.Close();
shadowBottom = null;
}
// override WndProc and insert the following:
switch(m.Msg)
{
case API.WM_MOVING:
case API.WM_SIZING:
case API.WM_SIZE:
case API.WM_WINDOWPOSCHANGED:
API.RECT rc = new API.RECT();
API.GetWindowRect(Handle, ref rc);
if(shadowRight != null)
{
shadowRight.RenderShadow(rc.ToRectangle(), true);
}
if(shadowBottom != null)
{
shadowBottom.RenderShadow(rc.ToRectangle(), true);
}
base.WndProc(ref m);
break;
default:
base.WndProc(ref m);
break;
}
// event handlers:
private void OnPaintRightShadow(object sender, PaintEventArgs pe)
{
// TODO: Paint your right edge shadow here.
}
private void OnPaintBottomShadow(object sender, PaintEventArgs pe)
{
// TODO: Paint your bottom edge shadow here.
}
VB
' at the top of source code file:
Imports NETXP.Library
Imports NETXP.Win32
' inside custom control class:
Private ShadowBottom As ShadowWindow
Private ShadowRight As ShadowWindow
' inside the overridden OnHandleCreated method:
ShadowRight = New ShadowWindow(Handle)
ShadowBottom = New ShadowWindow(Handle)
ShadowRight.ShadowType = ShadowType.Right
ShadowBottom.ShadowType = ShadowType.Bottom
' handle PaintShadow for each shadow window
AddHandler ShadowRight.PaintShadow, AddressOf OnPaintRightShadow
AddHandler ShadowBottom.PaintShadow, AddressOf OnPaintBottomShadow
' show the shadow windows
ShadowRight.Show()
ShadowBottom.Show()
' inside the overridden OnHandleDestroyed method:
If Not ShadowRight Is Nothing Then
ShadowRight.Close()
ShadowRight = Nothing
End If
If Not ShadowBottom Is Nothing Then
ShadowBottom.Close()
ShadowBottom = Nothing
End If
' override WndProc and insert the following:
If m.Msg = API.WM_MOVING Or m.Msg = API.WM_SIZING Or m.Msg = API.WM_SIZE
Or m.Msg = API.WM_WINDOWPOSCHANGED Then
Dim rc As New API.RECT()
API.GetWindowRect(Handle, rc)
If Not ShadowRight Is Nothing Then
ShadowRight.RenderShadow(rc.ToRectangle(), True)
End If
If Not ShadowBottom Is Nothing Then
ShadowBottom.RenderShadow(rc.ToRectangle(), True)
End If
End If
MyBase.WndProc(m)
' event handlers:
Private Sub OnPaintRightShadow(ByVal sender As Object, ByVal pe As
PaintEventArgs)
' TODO: Paint your right edge shadow here.
End Sub
Private Sub OnPaintBottomShadow(ByVal sender As Object, ByVal pe As
PaintEventArgs)
' TODO: Paint your bottom edge shadow here.
End Sub