Hello There, Guest! (LoginRegister)

Thread Closed 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to use CustomDrawItem
» Touch Controls Suite 1.x
Author Message
Sascha Lange Offline
Administrator
*******

Posts: 298
Joined: Dec 2008
Post: #1
How to use CustomDrawItem
First of all you need to change the DrawMode to OwnerDraw:

Visual C# Code:
touchListBox1.DrawMode = TouchListBox.DrawModes.OwnerDraw;

Now you can use the CustomDrawItem event to custom draw your items:

Visual C# Code:

private void touchListBox1_CustomDrawItem(object sender, int Index, Graphics g, Rectangle rect, bool isSelected)
{

if (isSelected)
{
// Highlight selected item
Brush backgroundColorSelected = new SolidBrush(Color.Red);
g.FillRectangle(backgroundColorSelected, rect);

// Draw Text
Font fontSelected = new Font(this.Font.Name, 8, FontStyle.Regular);
Brush fontSelectedColor = new SolidBrush(Color.White);
g.DrawString(touchListBox1.Items[Index].Text, fontSelected, fontSelectedColor, rect.Left + 20, rect.Top + 5);
// Draw more text
g.DrawString("Subtext "+Index.ToString(), fontSelected, fontSelectedColor, rect.Left + 20, rect.Top + 15);
g.DrawString("More subtext " + Index.ToString(), fontSelected, fontSelectedColor, rect.Left + 20, rect.Top + 25);

}
else
{
if (Index % 2 == 1)
{
// Background color for each second item
Brush backgroundColor = new SolidBrush(Color.LightGray);
g.FillRectangle(backgroundColor, rect);
}
else
{
// default background color
Brush backgroundColorDefault = new SolidBrush(Color.White);
g.FillRectangle(backgroundColorDefault, rect);
}

// Draw Text
Font font = new Font(this.Font.Name, 8, FontStyle.Regular);
Brush fontColor = new SolidBrush(Color.Black);
g.DrawString(touchListBox1.Items[Index].Text, font, fontColor, rect.Left + 20, rect.Top + 5);
// Draw more text
g.DrawString("Subtext " + Index.ToString(), font, fontColor, rect.Left + 20, rect.Top + 15);
g.DrawString("More subtext " + Index.ToString(), font, fontColor, rect.Left + 20, rect.Top + 25);
}

// Draw icon
AlphaImageClass.IImage icon = AlphaImageClass.GetAlphaImageFromBytes(Properties.Resources.icon);
AlphaImageClass.DrawAlphaImage(icon, g, rect.Right - 40 , rect.Top + 4);

}
}


mirabyte Software-Entwickler / Software-Engineer
(This post was last modified: 30-03-2010 09:18 by mirabyte Support.)
21-10-2009 01:09
Find all posts by this user
Thread Closed