Layers Example
Details
Date:2/15/2012 4:42:00 AM
Product:ActiveGanttCSN Gantt Chart / Scheduler Component
Framework:.Net Framework 4.0 / Visual Studio 2010
Version:2.8.6
User's Development Environment:C# Visual Studio 2010
Subject:Layers Example
Question

I want to present a task with different durations. For example, task is done in two durations: 01.02.2012-04.02.2012 and 10.2.2012-18.02.2012. I want to draw it in the same row.

From the introduction of ActiveGantt, I think the layer collection maybe can help me. So could you send me an example about this object.

Answer

Answer:

Create a new Windows form with:

The CheckBoxes will control the visibility of the Layer objects.

The RadioButtons will control which Layer is the current layer for the control.

In the Form Load event add the following code:


        private void fLayers_Load(object sender, EventArgs e)
        {
            clsStyle oStyle;
            ActiveGanttCSNCtl1.Columns.Add("", "C1", 125, "");
            ActiveGanttCSNCtl1.Rows.Add("K1", "Row 1", true, true, "");
            ActiveGanttCSNCtl1.CurrentViewObject.Interval = "1h";
            ActiveGanttCSNCtl1.CurrentViewObject.TimeLine.TickMarkArea.Visible = false;
            ActiveGanttCSNCtl1.CurrentViewObject.TimeLine.TierArea.TierFormat.DayOfWeekIntervalFormat = "%d";
            ActiveGanttCSNCtl1.CurrentViewObject.TimeLine.Position(new DateTime(2012, 2, 1));
            ActiveGanttCSNCtl1.Layers.Add("Layer1", true);
            ActiveGanttCSNCtl1.Layers.Add("Layer2", true);
            oStyle = ActiveGanttCSNCtl1.Styles.Add("Layer1Style");
            oStyle.Appearance = E_STYLEAPPEARANCE.SA_FLAT;
            oStyle.BackGroundMode = GRE_BACKGROUNDMODE.FP_SOLID;
            oStyle.BackColor = Color.Red;
            oStyle.Placement = E_PLACEMENT.PLC_OFFSETPLACEMENT;
            oStyle.OffsetTop = 5;
            oStyle.OffsetBottom = 5;
            oStyle = ActiveGanttCSNCtl1.Styles.Add("Layer2Style");
            oStyle.Appearance = E_STYLEAPPEARANCE.SA_FLAT;
            oStyle.BackGroundMode = GRE_BACKGROUNDMODE.FP_SOLID;
            oStyle.BackColor = Color.Blue;
            oStyle.Placement = E_PLACEMENT.PLC_OFFSETPLACEMENT;
            oStyle.OffsetTop = 15;
            oStyle.OffsetBottom = 5;
            ActiveGanttCSNCtl1.Tasks.Add("", "K1", new DateTime(2012, 2, 1), new DateTime(2012, 2, 4), "", "Layer1Style", "Layer1");
            ActiveGanttCSNCtl1.Tasks.Add("", "K1", new DateTime(2012, 2, 1), new DateTime(2012, 2, 18), "", "Layer2Style", "Layer2");
            ActiveGanttCSNCtl1.CurrentLayer = "Layer1";
        }

This will create two layers and two style objects for each of the layers and two tasks (each one in a separate layer).

To hide or show the layers use the CheckBox’s Checked changed event:



        private void chkLayer2_CheckedChanged(object sender, EventArgs e)
        {
            ActiveGanttCSNCtl1.Layers.Item("Layer2").Visible = chkLayer2.Checked;
            ActiveGanttCSNCtl1.Redraw();

        }

        private void chkLayer1_CheckedChanged(object sender, EventArgs e)
        {
            ActiveGanttCSNCtl1.Layers.Item("Layer1").Visible = chkLayer1.Checked;
            ActiveGanttCSNCtl1.Redraw();
        }

To specify the default layer use the RadioButton’s Checked changed event:



        private void optLayer1_CheckedChanged(object sender, EventArgs e)
        {
            if (optLayer1.Checked == true)
            {
                ActiveGanttCSNCtl1.CurrentLayer = "Layer1";
            }
        }

        private void optLayer2_CheckedChanged(object sender, EventArgs e)
        {
            if (optLayer2.Checked == true)
            {
                ActiveGanttCSNCtl1.CurrentLayer = "Layer2";
            }
        }

You will get this output:

Notice that you will be able to move both tasks and not generate any sort of conflict.

Now when an object is added, this code:



        private void ActiveGanttCSNCtl1_ObjectAdded(object sender, ObjectAddedEventArgs e)
        {
            if (e.EventTarget == E_EVENTTARGET.EVT_TASK)
            {
               if (ActiveGanttCSNCtl1.CurrentLayer == "Layer1")
                {
                    ActiveGanttCSNCtl1.Tasks.Item(e.TaskIndex.ToString()).StyleIndex = "Layer1Style";
                }
                else if (ActiveGanttCSNCtl1.CurrentLayer == "Layer2")
                {
                    ActiveGanttCSNCtl1.Tasks.Item(e.TaskIndex.ToString()).StyleIndex = "Layer2Style";
                }
            }
        }

Sets the style index of the newly created task object to the style being used by the default layer object.

Tasks that are created in the user interface (non-programmatically) will be added to the default layer object (the CurrentLayer property determines which layer).

Under this scenario tasks will only generate conflicts if they are located in the same layer.

 

All trademarks are property of their respective holders, and are only used to directly describe the products and services being provided. Their use in no way indicates any relationship or endorsement between The Source Code Store LLC and the holders of said trademarks.