Search
C# Quick Start

To use FlowChartX ActiveX Control under C# with Microsoft Visual Studio 7 follow these steps:

Creating new project.

In the VS environment create a new project with "File -> New -> Project". In the dialog box that appears, select "Visual C# Projects" from Project Types list and "Windows Application" from Templates list. Give your project a suitable name and click OK. The wizard creates a new project for you.

Adding the FlowChartX control to the project.

You can customize the project form name and appearance as you wish. To add FlowChartX control to the form, right-click "Windows Forms" tab, which stays under Toolbox docking bar. If Toolbox bar is not visible, you can make it appear choosing "View -> Toolbox" menu. Afterwards, right-click inside the Toolbox area to show its context menu, and select "Customize...". From ActiveX control list check FlowChartX control and click OK button. If FlowChartX is not in the list, make sure you have run FlowChartX installation program to register the control.

You can write your initialization code right after InitializeComponent method is invoked in the Form constructor. For example, you can set default values for FlowChartX objects and/or initialize FlowChartX document - size, position, background color/image.

Customizing the application form.

After adding the FlowChartX control to the Toolbox, you can place it in the form layout. The C# environment automatically generates a member variable for the control in your form class. In addition to the FlowChartX control, you can add some UI components to carry out additional program functionality. In our example two buttons for easier interaction with the program are inserted - 'Mod' and 'Out'. That's how our form looks so far:

Working with object collections.

Now, with buttons ready, add some functionality to them by creating their event handlers. Double-clicking each of the buttons automatically adds Mod_Click and Out_Click methods to your form class, considering the buttons' names are respectively 'Mod' and 'Out'. The first button modifies the appearance of all selected boxes while the second one selects all outgoing arrows of active selected box in the current selection. Following code snippet illustrates that:

C#  Copy Code

private void Mod_Click(object sender, System.EventArgs e)
{
    // Iterate through all selected boxes in
    // the FlowChart SelectedBoxes collection and
    // change their appearance.
    foreach (FLOWCHARTLib.box box in this.axFlowChart1.SelectedBoxes)
    {
        box.PenWidth = 3;
        box.FillColor = 0x00FFFF; // Yellow color
        box.FrameColor = 0xFF0000; // Blue color
    }
}

private void Out_Click(object sender, System.EventArgs e)
{
    // Check whether there is selected box
    if (this.axFlowChart1.ActiveBox != null)
    {
        // Get the selected box
        FLOWCHARTLib.box box = this.axFlowChart1.ActiveBox;

        // Clear the current selection
        this.axFlowChart1.ClearSelection();

        // Select all outgoing arrows for the selected box
        // while iterating through the selected box
        // OutgoingArrows collection
        foreach(FLOWCHARTLib.Arrow arrow in box.OutgoingArrows)
            this.axFlowChart1.AddToSelection(arrow);
    }
    else
    {
        // If the selected box is not present, inform the user
        MessageBox.Show ("Select a box first!", "Form1", 
            MessageBoxButtons.OK, MessageBoxIcon.Information);
    }
}

Handling FlowChartX control events.

Following steps illustrate FlowChartX events handling. In dialog editor environment select FlowChartX control. Now go to the Properties bar and click "Events" button. If Properties bar is not visible, you can access it through "View -> Properties Window". All specific FlowChartX events are listed under Misc section. Choose which events you would like to handle and insert event handlers for them. In our example we add a handler for BoxDblClicked event, which is raised when the user double-clicks a box in the control. In the edit box placed on right side of the event name type your event handler name, for example OnBoxDblClicked. Event handler declaration is automatically placed at the bottom of your Form class. In order to add functionality to the handler method go to Form class' source code. Following code snippet  shows a confirmation dialog box, which asks the user whether they want to delete the double-clicked box:

C#  Copy Code

private void OnBoxDblClicked(object sender, AxFLOWCHARTLib._IFlowChartEvents_BoxDblClickedEvent e)
{
    if (MessageBox.Show ("Are you sure you want to " +
        "delete the selected box?", "Form1",
        MessageBoxButtons.OKCancel, MessageBoxIcon.Question) ==
        DialogResult.OK)
    {
        // The double-clicked box can be found as one
        // of the event members.
        this.axFlowChart1.DeleteItem(e.pBox);
    }
}