Programmatically define Activity color and layout
When using the workflow authoring API to programmatically define a workflow, you may want to set an activity's colors or location of the activity on the canvas. The following code sample demonstrates how you can work with the layout of activities programmatically.
This code snippet requires references the assemblies:
- SourceCode.Workflow.Authoring
- SourceCode.Workflow.Design
- System.Drawing
Process k2Process = SourceCode.Workflow.Authoring.Process.Load("[filename");
//load the activity you want to work with. In this example we grab the first activity
Activity act = k2Process.Activities[0];
//instantiate a ProcessViewActivityLayoutData object that defines the layout of an activity on the canvas
ProcessViewActivityLayoutData actLayout = new ProcessViewActivityLayoutData();
//load up an activity object by Guid if you want to work with an existing activity
actLayout.Name = "{" + act.Guid.ToString() + "}";
//if you want to set the location of the activity, define it in x, y coordinates
int x = 100;
int y = 200;
actLayout.Location = new System.Drawing.Point(x, y);
//apply a colour to the activity
actLayout.MainColor = System.Drawing.Color.DarkBlue;
//add layout data to the process
((ProcessView) k2Process.Views[0]).ActivitiesLayoutData.Add(actLayout);