index > Visual Studio Team System - Domain-Specific Language Tools > Changing image displayed by image shape programmatically

Changing image displayed by image shape programmatically


Hi all,

The dsl i am working on uses an image shape. I would like to change the image displaed by the image shape at runtime.

Is it possible??

Freddo

Freddo

Hi Freddo,

It is possible to add an image programmatically to an image shape. First, you need to mark the ImageShape property "HasDoubleDerived" as true and regenerate the code by Transforming the Shape.tt template. Then, add a new custom class (say MyShapeName.cs) to your project and make it derive from MyShapeNameBase.cs (in the generated Shape.cs). Then override the Image getter in the derived class and return any System.Drawing.Image object from this method that will be used as an Image for your shape.

E.g. code snippet will look similar to this:

namespace Microsoft.Language16Shapes
{
public partial class ConditionShape : ConditionShapeBase
{
/// <summary>
/// Provide the specific Image for this Shape class
/// </summary>
protected override global::System.Drawing.Image Image
{
get
{

//Here you can give any implementation that will select the right image based on your requirements.
global::System.Resources.ResourceManager resourceManager = global::Microsoft.Language16.Language16DomainModel.SingletonResourceManager;
return DslDiagrams::ImageHelper.GetImage(resourceManager.GetObject("PortParentExplorerImage"));
}
}
}
}

Hope this helps,

Bhavin B

DSL Tools - SDET

Bhavin B

Hi Bhavin B,

Thank you for the rapid response. The solution that you provided work fine but does not provide the possibility to change the image displayed by the image shape after the image shape has been initialized. This is the functionality I was really looking for.

Do you think it is possible?

Freddo

Freddo

I cannot think of any way that you can change the image dynamically at runtime. Sorry. I will let you know if I find out about a way to do this.

Thanks,

Bhavin.

Bhavin B

Hi Freddo,

One way you can try is to create your own geometry (inherited from ImageShapeGeometry) for the image shape(see here), and override the DoPaintGeometry() method to draw different images at runtime.

Regards,
Steven




DSL Tools - SDE Intern
Steven Tung

Hi Steven,

You are right. However, I found that by simply overriding the ShapeGeometry property of my image shape as follow also do the trick.  

public override DslDiagrams:elp:ShapeGeometry ShapeGeometry

{

get

{

return new DslDiagrams::ImageShapeGeometry(this.Image);}

}

Obviously, you also need  to override the Image property of the image shape as suggested by Bhavin ealier.

 Freddo

Freddo
reply 6

You can use google to search for other answers

 

More Articles

constrain the number of a specific shape
DSL Setup project fails to compile
toolbox problem - reset toolbox doesn't work
Setup & life cycle
DoubleClick in Compartment item
Orchestration Features
What one-shot recipes would you add to DSL Designer?
Announcing DSL Tools May 2005 CTP for Visual Studio 2005 Beta 2
Context menu item localization
DSLTools download moved?
Welcome to Bokebb   New Update   Joins the collection  
 

New Articles

Show or Hide icon decorator at runtime
Properties on Relationship
Accessing the domain model using code
What is the best way to present 3 value …
Referencing Domain Classes from Domain P…
Can Visual Studio DSL Designers be hosted?
DMD -> DD
Have problem for the DSL walk-through st…
DSL interacting with VS project system.
Abstract classes in minimal language
Installation Problems? "operation i…
Open Source Designer
Multiple viewpoints/ zoom in, zoom out
Experience report: Building my own DSL
CMDS: Missing package guid for commands …

Hot Articles

DSL and visual studio
How to Add context menu to shapes
Modal EditStyle and enumerations
Shape Icon and Shape Tool Minor Bug
accessing relations (and its value prope…
Custom connector target (June CTP)
DSL Tools November CTP now available
blog post suggestions: mdfddt/mdfomt fil…
How to know if OnShapeInserted was initi…
Bug in Edit Attributes editor
Changing elements from properties
Nested Diagram
Shape position from a template...
Troubleshooting: duplicate generated files
Possible to get samples with new DSL inc…

Recommend Articles

Controlling Font
Model Query Capabilities
Troubleshooting: replicating toolbox items
Validation Framework
How to change the Name property when a S…
How to Export diagram as image
Problem creating a DSL project
domain class inheritance, where types ar…
How to clip shape text?
Problems with DSL Tools walk-through
Show more than one Property in a Compart…
Embedding shapes in v1
Problem with the VS SDK March 2006
Unable to Replace Old Files by New ones
Instanciate an external model