Search
Important Notes for .NET Users

Accessing hidden properties

When FlowChartX is imported by the .NET environment in a C# or VB.NET project a wrapper class derived from AxHost is created. The AxHost class has members BackColor and Font that overcast FlowChartX properties with the same names. To access them you have to use variable of type IFlowChart, as shown in the following C# example:

C#  Copy Code

FLOWCHARTLib.IFlowChart fc = (FLOWCHARTLib.IFlowChart)axFlowChart1.GetOcx();
Color c = Color.FromArgb(200, 40, 40);

fc.BackColor = (uint)ColorTranslator.ToOle(c);
fc.Font.Bold = true;
fc.Font.Size = 22;

The axFlowChart1 variable is an object of the class imported by the .NET environment. Its GetOcx method returns a reference to the underlying control and the fc assignment queries it for the IFlowChart interface. The given example also illustrates how to work with FlowChartX color properties. .NET imports OLE_COLOR type as uint and System.Drawing.Color.ToOle method returns int, so a cast is needed.

Setting images and fonts of objects

There are some issues to note when working with images. In the imported FlowChart class the Picture property is of type System.Drawing.Image and you can use all Image class static members to load this Picture. The Box object Picture property on the other hand is imported as stdole.IPictureDisp and you have two options for loading images into it:

  • use the box' LoadPicture method
  • use the AxHost.GetIPictureDispFromPicture method. Since it is a protected method it can be accessed only via an AxHost derived class.

Both ways to loading a picture are shown below:

C#  Copy Code

axFlowChart1.Picture = Image.FromFile("ag01.jpg");
axFlowChart1.Boxes[0].LoadPicture("ag02.jpg");
axFlowChart1.Boxes[1].Picture = Converter.Convert(Image.FromFile("ag03.jpg"));

Here is the definition of the Converter class, which also can convert from .NET fonts to OLE fonts:

C#  Copy Code

internal class Converter : AxHost
{
    public Converter(): base("")
    {
    }

    public static stdole.IPictureDisp Convert(Image image)
    {
        return (stdole.IPictureDisp)AxHost.GetIPictureDispFromPicture(image);
    }

    public static stdole.IFontDisp Convert(Font font)
    {
        return (stdole.IFontDisp)AxHost.GetIFontDispFromFont(font);
    }
}