index > Visual Studio Team System - Domain-Specific Language Tools > Background Picture

Background Picture


How could you add a background image to the diagram canvas as a whole?
Jezz Santos

[Obsolete answer - see the new version following.]

 ...




- Alan [Microsoft]
Alan Cameron Wills

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]
Alan Cameron Wills
reply 3

You can use google to search for other answers

 

More Articles

·Unable to Start Debugging !!!
·IsSerializing property
·DSL Tools for RTM?
·Rules in DSL Tools V1
·Fatal error CTC2114 when compiling wizard-generated DSLs
·Compartment Shape for Model
·How to categorize properties?
·DSL and XMI interchange format
·Creating A connector to CompartMent Items
·Text template load a file
Welcome to Bokebb   New Update   Joins the collection  
 

New Articles

·cannot drag & drop shape from toolbox
·newbie question,thank you for your atten¡­
·Migrating compartments
·Decorator for Compartments
·How to make Multiple Views
·Define a menu command
·Template transformation error in designe¡­
·Are there any Community Projects using t¡­
·DSL for existing descriptive language
·Show more than one Property in a Compart¡­
·DSL Toolkit - March version
·How create an Emf file ? Extending notat¡­
·DSL Tools May 2005 with VSTS July CTP?
·DSL Designer architecture
·Connectors connecting to connectors

Hot Articles

·DSL Tools Sept CTP and WinFX Sept CTP?
·DSL Tools for RTM?
·Unable to Start Debugging !!!
·How are new objects created in a DSL?
·Getting validation results
·Change a connector's from and to endpoin¡­
·Concepts behind the design of DSL tools
·DSL & Automation
·Experimental UI - show and hide shapes a¡­
·How to set formatting to the strings dis¡­
·Syntax coloring for .ReportTemplate (T3)¡­
·Shape position from a template...
·Programmatically creating diagrams
·Walkthrough distinguish visually between¡­
·Package Load Failure

Recommend Articles

·Custom rules
·What is the best way to present 3 value ¡­
·Problem creating a DSL project
·Package Load Failure
·How can i associate a textfield with a p¡­
·Add a toolbar to the dsl designer surface
·XML editor starts DSL model, but I want ¡­
·November 2005 CTP available
·Shape position from a template...
·Use of the TextTransform tool
·schedule for beta and V1 releases?
·VS SDK March 2006 CTP
·What to use instead of GetDisplayPropert¡­
·Embedding shapes in v1
·Problems with DSL Tools Version 1