private static IDisposable DrawBackDarkEdge(RectangleF drawRect,
Color color1,
int thickness,
VisualOrientation orientation,
Graphics g,
IDisposable memento)
{
// Cannot draw a zero length rectangle
if ((drawRect.Width > 0) && (drawRect.Height > 0))
{
bool generate = true;
MementoBackDarkEdge cache;
// Access a cache instance and decide if cache resources need generating
if ((memento == null) || !(memento is MementoBackDarkEdge))
{
if (memento != null)
memento.Dispose();
cache = new MementoBackDarkEdge(drawRect, color1, thickness, orientation);
memento = cache;
}
else
{
cache = (MementoBackDarkEdge)memento;
generate = !cache.UseCachedValues(drawRect, color1, thickness, orientation);
}
// Do we need to generate the contents of the cache?
if (generate)
{
// Dispose of existing values
cache.Dispose();
// If we need to scale down the dark thickness
if (VerticalOrientation(orientation))
{
if (drawRect.Height < 30)
thickness = (int)drawRect.Height / 10;
}
else
{
if (drawRect.Width < 30)
thickness = (int)drawRect.Width / 10;
}
// If there is something to draw
if (thickness >= 0)
{
// Alter rectangle to the drawing edge only
switch (orientation)
{
case VisualOrientation.Top:
drawRect.Height = thickness;
break;
case VisualOrientation.Left:
drawRect.Width = thickness;
break;
case VisualOrientation.Bottom:
drawRect.Y = drawRect.Bottom - thickness - 1;
drawRect.Height = thickness + 1;
break;
case VisualOrientation.Right:
drawRect.X = drawRect.Right - thickness - 1;
drawRect.Width = thickness + 1;
break;
}
// Create rectangle that covers the enter area
RectangleF gradientRect = new RectangleF(drawRect.X - 0.5f, drawRect.Y - 0.5f, drawRect.Width + 1, drawRect.Height + 1);
// Cannot draw a zero length rectangle
if ((gradientRect.Width > 0) && (gradientRect.Height > 0))
{
// Draw entire area in a gradient color effect
cache.entireBrush = new LinearGradientBrush(gradientRect, Color.FromArgb(64, color1), Color.Transparent, AngleFromOrientation(orientation));
cache.entireBrush.SetSigmaBellShape(1.0f);
cache.entireRect = drawRect;
}
}
}
if (cache.entireBrush != null)
g.FillRectangle(cache.entireBrush, cache.entireRect);
}
return memento;
}