Skybound AutoComplete

DrawItemEventHandler Delegate

Represents the method that will handle the DrawItem event of an AutoCompleteManager.

[Visual Basic]
Public Delegate Sub DrawItemEventHandler( _
   ByVal sender As Object, _
   ByVal e As DrawItemEventArgs _
)
[C#]
public delegate void DrawItemEventHandler(
   object sender,
   DrawItemEventArgs e
);

Parameters

sender
The source of the event.
e
A DrawItemEventArgs that contains the event data.

Example

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

Requirements

Namespace: Skybound.AutoComplete

Assembly: Skybound.AutoComplete (in Skybound.AutoComplete.dll)

See Also

Skybound.AutoComplete Namespace