void DrawDropLine(Graphics g, int index, bool drawLine, HitTestType hit)
{
Brush brush = null;
Pen pen = null;
try
{
if (drawLine)
{
droppedPosition = index;
lastDrawnLineIndex = index;
brush = SystemBrushes.ControlText;
pen = SystemPens.ControlText;
}
else
{
// If there is nothing painted, no need to erase
if (lastDrawnLineIndex == -1)
return;
index = lastDrawnLineIndex;
brush = new SolidBrush(bands[currentBandIndex].Background);
pen = new Pen(bands[currentBandIndex].Background);
lastDrawnLineIndex = -1;
}
int itemsCount = bands[currentBandIndex].Items.Count;
Rectangle itemRect = GetItemRect(g, bands[currentBandIndex], index, Rectangle.Empty);
Rectangle viewPortRect = GetViewPortRect();
int y;
if (bands[currentBandIndex].IconView == IconView.Small)
y = itemRect.Top - Y_SMALLICON_SPACING / 2;
else
y = itemRect.Top - Y_LARGEICON_SPACING;
if (hit == HitTestType.DropLineLastItem)
{
// use the bottom of the label if dealing with the last item
Rectangle labelRect = GetLabelRect(itemsCount - 1);
y = labelRect.Bottom + Y_LARGEICON_SPACING;
paintedDropLineLastItem = true;
// the none existing item index
droppedPosition = itemsCount;
}
else if (paintedDropLineLastItem)
{
Rectangle labelRect = GetLabelRect(itemsCount - 1);
y = labelRect.Bottom + Y_LARGEICON_SPACING;
paintedDropLineLastItem = false;
}
// If we are using a bitmap background, erase
// by painting the portion of the bitmap background
if (backgroundBitmap != null && lastDrawnLineIndex == -1)
{
Rectangle rcStrip = new Rectangle(viewPortRect.Left, y - 6, viewPortRect.Width, 12);
g.DrawImage(backgroundBitmap, rcStrip, rcStrip, GraphicsUnit.Pixel);
return;
}
// Draw horizontal line
Point p1 = new Point(viewPortRect.Left + 11, y);
Point p2 = new Point(viewPortRect.Right - 11, y);
g.DrawLine(pen, p1, p2);
// Draw left triangle
Point top;
Point bottom;
if (index == firstItem)
top = new Point(viewPortRect.Left + 5, y);
else
top = new Point(viewPortRect.Left + 5, y - 6);
if (hit == HitTestType.DropLineLastItem)
bottom = new Point(viewPortRect.Left + 5, y + 1);
else
bottom = new Point(viewPortRect.Left + 5, y + 6);
Point middle = new Point(viewPortRect.Left + 11, y);
Point[] points = new Point[3];
points.SetValue(top, 0);
points.SetValue(middle, 1);
points.SetValue(bottom, 2);
g.FillPolygon(brush, points);
// Draw right triangle
if (index == firstItem)
top = new Point(viewPortRect.Right - 5, y);
else
top = new Point(viewPortRect.Right - 5, y - 6);
if (hit == HitTestType.DropLineLastItem)
bottom = new Point(viewPortRect.Right - 5, y + 1);
else
bottom = new Point(viewPortRect.Right - 5, y + 6);
middle = new Point(viewPortRect.Right - 11, y);
points.SetValue(top, 0);
points.SetValue(middle, 1);
points.SetValue(bottom, 2);
g.FillPolygon(brush, points);
}
finally
{
if (!drawLine)
{
brush.Dispose();
pen.Dispose();
}
}
}