Infralution Support Forum Index Infralution Support
Support groups for Infralution products
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Icon in a cell?

 
Post new topic   Reply to topic    Infralution Support Forum Index -> Virtual Tree Support
View previous topic :: View next topic  
Author Message
flc.net
Guest





PostPosted: Thu Jun 16, 2005 12:00 pm    Post subject: Icon in a cell? Reply with quote

Hi

It's possible to add an icon in a cell (not in the main column)?

thanks
Back to top
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Thu Jun 16, 2005 10:56 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Infralution Support Forum Index -> Virtual Tree Support All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group