table heading image

Developer
May 19, 2011 at 11:27 AM

In order to show an image in table headers (the same way they are shown in table rows) a few changes must be made:

Add the following to the Table.cs, in Crainiate.Diagramming,

// table property variables
private Image _headingimage;

// table constructor Table(Table prototype)
if ( prototype.HeadingImage != null ) HeadingImage = ( Image ) prototype.HeadingImage.Clone ( );

// table properties
public virtual Image HeadingImage
{
    get { return _headingimage; }
    set
    {
        if ( _headingimage != null )
        {
            _headingimage.ImageInvalid -= new EventHandler ( HeadingImage_ImageInvalid );
        }
        _headingimage = value;
        if ( _headingimage != null )
        {
            _headingimage.ImageInvalid += new EventHandler ( HeadingImage_ImageInvalid );
            _headingimage.SetParent ( this );
        }

        OnElementInvalid ( );
    }
}

// table events
void HeadingImage_ImageInvalid ( object sender, EventArgs e )
{
    OnElementInvalid ( );
}

and in the TableRender.cs, in Crainiate.Diagramming.Forms.Rendering, in method RenderTable replace the 'Draw heading text' block (aprox. line 132) with the following

//Draw image
float imageWidth = 0;
if ( table.HeadingImage != null && table.HeadingImage.Bitmap != null )
{
    System.Drawing.Image bitmap = table.HeadingImage.Bitmap;

    //Work out position of image
    float imageTop = ( table.HeadingHeight / ( table.SubHeading.Trim ( ).Length > 0 ? 2 : 1 ) - bitmap.Height ) / 2;
    if ( imageTop < 0 ) imageTop = 0;

    imageWidth = bitmap.Width;
    graphics.DrawImageUnscaled ( bitmap, 8, Convert.ToInt32 ( imageTop ) );
}

//Draw Heading text
brush.Color = render.AdjustColor(table.Forecolor, 1, table.Opacity);
graphics.DrawString(table.Heading, Singleton.Instance.GetFont(table.FontName, table.FontSize, FontStyle.Bold), brush, 8 + imageWidth, 5);
if ( table.SubHeading.Trim ( ).Length > 0 )
{
    graphics.DrawString ( table.SubHeading, Singleton.Instance.GetFont ( table.FontName, table.FontSize - 1, FontStyle.Regular ), brush, 8, 20 );
}