Provides data for the DrawItemEventHandler event.
For a list of all members of this type, see DrawItemEventArgs Members.
System.Object
System.EventArgs
Skybound.AutoComplete.AutoCompleteEventArgs
Skybound.AutoComplete.MeasureItemEventArgs
Skybound.AutoComplete.DrawItemEventArgs
Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.
The DrawItem event is raised by the AutoCompleteManager component when an item is drawn. It contains all the information needed to paint the specified item, including its index, text, and value, as well as the bounding Rectangle and the Graphics surface on which the drawing is done.
Double-buffering is a technique that eliminates flicker by drawing to an offscreen buffer first, and then copying the context of the buffer to the screen. However, it uses more memory and incurs a small performance penalty. You can enable double-buffering by setting DoubleBuffer to true.
This is an example handler for the DrawItem event. It draws the background of the highlight bar using a gradient fill, and displays the file size or "Folder" beside each item in the list (depending on what it is). We are assuming in this example that files are being suggested in the drop-down suggestion window.
[C#]
private void autoComplete1_DrawItem(object sender, Skybound.AutoComplete.DrawItemEventArgs e)
{
bool selected = (e.State & DrawItemState.Selected) == DrawItemState.Selected;
if (selected)
{
// make a gradient highlight brush
using (Brush brush = new LinearGradientBrush(
e.Bounds, SystemColors.Highlight, ControlPaint.Light(SystemColors.Highlight),
LinearGradientMode.Vertical))
{
e.Graphics.FillRectangle(brush, e.Bounds);
}
}
else
{
e.DrawBackground();
}
// draw image and text
e.DrawImage(e.Bounds.Location + new Size(4, 0));
e.DrawText(e.Bounds.Location + new Size(22, 1));
// get the full path to the file
string fileName = e.GetFullPath();
if (fileName != null)
{
string extra;
// retrieve information about the file
FileInfo info = new FileInfo(fileName);
if ((info.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
{
extra = "Folder";
}
else
{
extra = (info.Length / 1024).ToString("#,##0") + " KB";
}
// draw the additional information directly in front of the other text
Point location = new Point(e.Bounds.X + e.MeasureText().Width + 28, e.Bounds.Y + 1);
e.DrawText(location, extra, selected ? Color.LightGray : Color.Gray);
}
}
[Visual Basic]
Private Sub autoComplete1_DrawItem(ByVal sender As Object, _
ByVal e As Skybound.AutoComplete.DrawItemEventArgs)
Dim selected As Boolean = ((e.State And DrawItemState.Selected) = DrawItemState.Selected)
If selected Then
' make a gradient highlight brush
Dim brush As Brush = New LinearGradientBrush(e.Bounds, SystemColors.Highlight, _
ControlPaint.Light(SystemColors.Highlight), LinearGradientMode.Vertical)
e.Graphics.FillRectangle(brush, e.Bounds)
Else
e.DrawBackground
End If
' draw image and text
e.DrawImage((e.Bounds.Location + New Size(4, 0)))
e.DrawText((e.Bounds.Location + New Size(22, 1)))
' get the full path to the file
Dim fileName As String = e.GetFullPath
If (Not (fileName) Is Nothing) Then
Dim extra As String
' retrieve information about the file
Dim info As FileInfo = New FileInfo(fileName)
If ((info.Attributes And FileAttributes.Directory) = FileAttributes.Directory) Then
extra = "Folder"
Else
extra = ((info.Length / 1024).ToString("#,##0") + " KB")
End If
' draw the additional information directly in front of the other text
Dim location As Point = New Point((e.Bounds.X _
+ (e.MeasureText.Width + 28)), (e.Bounds.Y + 1))
e.DrawText(location, extra, IIf(selected, Color.LightGray, Color.Gray))
End If
End Sub
Namespace: Skybound.AutoComplete
Assembly: Skybound.AutoComplete (in Skybound.AutoComplete.dll)
DrawItemEventArgs Members | Skybound.AutoComplete Namespace