You can set a background picture in the whole diagram as shown here.
Add your picture to the Dsl Project resources:
- Copy the image file to the Dsl\Resources folder and include it in the Dsl project.
- Open the DSL Project properties by right clicking on the DSL project
- Go to the Resources tab and click to add the resources file, if necessary.
- Drag the image from the solution explorer into the resources file
Add a custom code file containing this:
[code]
using System;
using Microsoft.VisualStudio.Modeling.Diagrams;
// Fix the namespace
namespace Fabrikam.MyProject.Language1
{
// Fix the Diagram Class name - get it from GeneratedCode\Diagram.cs
public partial class Language1Diagram
{
protected override void InitializeInstanceResources()
{
base.InitializeInstanceResources();
// Fix the Resources namespace and the Image resource name.
ImageField backgroundField = new ImageField("background",
Fabrikam.MyProject.Language1.Properties. Resources.kathRowing);
backgroundField.DefaultFocusable = false;
backgroundField.DefaultSelectable = false;
backgroundField.DefaultVisibility = true;
backgroundField.DefaultUnscaled = false; // or true to use the natural size of the image without weird stretching
shapeFields.Add(backgroundField);
backgroundField.AnchoringBehavior.SetTopAnchor( AnchoringBehavior.Edge.Top, 0.01);
backgroundField.AnchoringBehavior.SetLeftAnchor( AnchoringBehavior.Edge.Left, 0.01);
backgroundField.AnchoringBehavior.SetRightAnchor( AnchoringBehavior.Edge.Right, 0.01);
backgroundField.AnchoringBehavior.SetBottomAnchor( AnchoringBehavior.Edge.Bottom, 0.01);
}
}
}
[/code]
The AnchoringBehavior stuff stretches the picture to fill the diagram. You might like to try variants for different effects.
(You can apply the same technique to individual shapes, but it's generally better to use an ImageShape, which is designed for the purpose.)
- Alan [Microsoft] |