private void smartTipListBox_DrawItem(object sender, DrawItemEventArgs e)
{
ListBox eObj = sender as ListBox;
e.DrawBackground();
string entireText = ((EntireInfo)eObj.Items[e.Index]).VarName;
int index = entireText.IndexOf(searchingStr, StringComparison.InvariantCultureIgnoreCase);
if (index >= )
{
TextFormatFlags formatFlags = TextFormatFlags.NoPadding | TextFormatFlags.SingleLine;
//TextFormatFlags formatFlags = TextFormatFlags.TextBoxControl | TextFormatFlags.WordBreak;
int leftAndTopPadding = ;
string headText = entireText.Substring(, index);
string matchedText = entireText.Substring(index, searchingStr.Length);
string tailText = entireText.Substring(index + matchedText.Length, entireText.Length - index - matchedText.Length);
int headTextPartWidth = TextRenderer.MeasureText(headText, e.Font, new Size(int.MaxValue, int.MaxValue), formatFlags).Width;
int highlightedTextWidth = TextRenderer.MeasureText(matchedText, e.Font, new Size(int.MaxValue, int.MaxValue), formatFlags).Width;
int yPosition = e.Index * smartTipListBox.ItemHeight + leftAndTopPadding;
int leftTextMargin = (int)( * e.Font.GetHeight() / );
int rightTextMargin = (int)( * e.Font.GetHeight() / );
if (index > )
{
TextRenderer.DrawText(e.Graphics, headText, e.Font, new Point(leftAndTopPadding, yPosition), Color.Black, formatFlags);
TextRenderer.DrawText(e.Graphics, matchedText, e.Font, new Point(leftAndTopPadding + headTextPartWidth - * leftTextMargin - rightTextMargin, yPosition), Color.Red, formatFlags);
TextRenderer.DrawText(e.Graphics, tailText, e.Font, new Point(leftAndTopPadding + headTextPartWidth + highlightedTextWidth - * leftTextMargin - * rightTextMargin, yPosition), Color.Black, formatFlags);
}
else
{
TextRenderer.DrawText(e.Graphics, matchedText, e.Font, new Point(leftAndTopPadding + headTextPartWidth, yPosition), Color.Red, formatFlags);
TextRenderer.DrawText(e.Graphics, tailText, e.Font, new Point(leftAndTopPadding + headTextPartWidth + highlightedTextWidth - * leftTextMargin - rightTextMargin, yPosition), Color.Black, formatFlags);
}
//Brush blackBrush = Brushes.Black;
//Brush redBrush = Brushes.Red;
//Rectangle initRectangle = e.Bounds;
//e.Graphics.DrawString(entireText.Substring(0, index), e.Font, blackBrush, initRectangle, null);
//initRectangle.Offset(Convert.ToInt32(e.Graphics.MeasureString(entireText.Substring(0, index), e.Font).Width), 0);
//e.Graphics.DrawString(entireText.Substring(index, searchingStr.Length), e.Font, redBrush, initRectangle, null);
//initRectangle.Offset(Convert.ToInt32(e.Graphics.MeasureString(entireText.Substring(index, searchingStr.Length), e.Font).Width), 0);
//e.Graphics.DrawString(entireText.Substring(index + searchingStr.Length, entireText.Length - index - searchingStr.Length), e.Font, blackBrush, initRectangle, null);
}
}