Search
VB Quick Start

Following section describes how to use FlowChartX ActiveX Control under Visual Basic.NET:

Creating new project.

In VisualStudio.NET environment open "File -> New -> Project". In the dialog box that appears, select "Visual Basic 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 FlowChart 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 Toolbox to show its context menu and choose "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 FlowChartX control is added to Toolbox, you can place it in the form layout. The Visual Basic.NET environment automatically generates a member variable for the control in your form class. In addition to 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 - 'Modify' and 'Incoming'.

Working with the object collections.

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

VB  Copy Code

Private Sub Modify_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Modify.Click

    Randomize()

    Dim box As FLOWCHARTLib.box
    For Each box In Me.AxFlowChart1.SelectedBoxes

        box.PenWidth = 3
        'box.FillColor = CType(Int((6 * Rnd()) + 1), UInt32)
        'box.FrameColor = CType(Int((6 * Rnd()) + 1), UInt32)

    Next

End Sub

Private Sub Incomming_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Incomming.Click

    Dim arrow As FLOWCHARTLib.Arrow
    Dim box As FLOWCHARTLib.box = Me.AxFlowChart1.ActiveBox

    ' Check whether there is selected box and notify user
    ' if there is no such box present
    If box Is Nothing Then

        MessageBox.Show("Select a box first!", "Form1", _
            MessageBoxButtons.OK, MessageBoxIcon.Information)

    Else

        ' Clear the FlowChart selection
        Me.AxFlowChart1.ClearSelection()

        ' Iterate through all incoming arrows for
        ' the selected box and add them to the FlowChart selection
        For Each arrow In box.IncomingArrows
            Me.AxFlowChart1.AddToSelection(arrow)
        Next

    End If

End Sub

Handling FlowChart control events.

To handle specific event for the FlowChartX, you need to do the following steps. Go to source code editor and from the form-objects combo box (placed in upper left corner) select AxFlowChart1. Choose the event you wish to handle from right combo box, which lists all corresponding to selected object events. Visual Basic.NET environment automatically adds the event-handler method in Form class. In our example we add BoxClicked event handler. First select the event in the combo box and AxFlowChart1_BoxClicked method automatically appears at the bottom of the Form class as shown below:

Finally add following few lines to the method implementation:

VB  Copy Code

Private Sub AxFlowChart1_BoxClicked(ByVal sender As Object, _
    ByVal e As AxFLOWCHARTLib._IFlowChartEvents_BoxClickedEvent) Handles AxFlowChart1.BoxClicked

    ' Now if the user right-clicked our box, we will
    ' change the box shape

    ' Check whether the user right-clicked the box
    If e.button = FLOWCHARTLib.EMouseButton.mbRight Then
        e.pBox.Style = (e.pBox.Style + 1) Mod 5
    End If

End Sub