Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Thu Jun 16, 2005 10:56 pm Post subject: |
|
|
You could do this in two ways:
1. Implement a System.Drawing.Design.UITypeEditor for the object type you are displaying in the cell and set the ShowPreview property of the cell to true. If your UITypeEditor supports custom painting then the preview will be displayed to the left of the text for the item. Here is an example of how you define a UITypeEditor that does custom painting:
Code: |
using System.Drawing.Design;
using System.Drawing;
class MyTypeEditor : UITypeEditor
{
public override bool GetPaintValueSupported(ITypeDescriptorContext)
{
return true;
}
public override void PaintValue(PaintValueEventArgs e)
{
// get your icon from somewhere based on the
// value of e.Value
Icon icon = ???;
e.Graphics.DrawIcon(icon, e.Bounds.X, e.Bounds.Y);
}
}
|
You associate the UITypeEditor with your type or property using the EditorAttribute eg
Code: |
[Editor(typeof(MyTypeEditor), typeof(UITypeEditor))]
class MyType
{
}
|
2. Implement your own custom drawing routine for Cells. You do this by inheriting a new class from CellWidget and then overriding the PaintForeground method eg
Code: |
using Infralution.Controls;
using Infralution.Controls.VirtualTree;
public class IconCellWidget : CellWidget
{
public IconCellWidget(RowWidget rowWidget, Column column)
: base(rowWidget, column) {}
protected override void PaintForeground(Graphics graphics, Style style, bool printing)
{
Rectangle bounds = Bounds;
// get your icon from somewhere maybe based on the
// value of CellData.Value
Icon icon = ???;
DrawingUtilities.DrawIcon(graphics, icon, bounds.X, bounds.Y, printing);
bounds.X += icon.Width;
bounds.Width -= icon.Width;
PaintText(graphics, style, bounds, printing);
}
}
|
To have VirtualTree use your new IconCellWidget you need to inherit from VirtualTree and override the CreateCellWidget method as follows:
Code: |
protected override CellWidget CreateCellWidget(RowWidget rowWidget, Column column)
{
return new IconCellWidget(rowWidget, column);
}
|
_________________ Infralution Support |
|