How to add icon near string for compartment item of CompartmentShape

Alex Mak 66 Reputation points
2025-11-03T15:27:00.3666667+00:00

Hello.

Please help, i have a situation:

  1. Create domain-specific language project type in VS 2022
  2. Then, i create my domain classes and shapes

here is picture of my setup:

User's image

As you can see - i have "Town" domain class, "Street" domain class and "TownCompartmentShape" compartmentShape and inside this shape i created Compartment field "Methods". And it works fine and i get "Town" (which is compartment shape like) and list of streets.

here is the picture of result:

User's image

And as you can see it works fine, but - i want to show little picture before name of each street, and I still can't figure it out - how to do this...

I tryed to create GeometryShape for "Street" domain class and connect "Street" to "StreetGeometryShape" but as a result i get one more rectangle with street name.

What is the best way to control drawing of each street? or what is the best way to specify picture before street name?

Please help.

Developer technologies | Visual Studio | Extensions
{count} votes

Answer accepted by question author
  1. Varsha Dundigalla(INFOSYS LIMITED) 3,480 Reputation points Microsoft External Staff
    2025-11-04T11:39:07.9633333+00:00

    Thank you for reaching out.

    You can add an icon before each compartment item by customizing the paint logic of the compartment. The correct way is to override the PaintItem method in the generated compartment class (derived from ElementListCompartment). This method is called for each item, so you can draw an image and then the text.

    Example syntax:

    
    protected override void PaintItem(Graphics g, Rectangle bounds, int index)
    {
        Image icon = Properties.Resources.MyStreetIcon; // your icon
        g.DrawImage(icon, bounds.Left, bounds.Top);
        bounds.X += icon.Width + 4; // shift text
        base.PaintItem(g, bounds, index);
    }
    
    

    Why this works: DSL Tools allow custom rendering by overriding paint methods. Creating a new GeometryShape won’t help because compartments don’t support embedded shapes. Overriding PaintItem is the simplest and supported approach.

    Reference:

    Here are the correct Microsoft Learn links for your scenario:

    These pages explain how to customize compartment shapes, override paint logic, and extend DSL projects in Visual Studio.

    Please let us know if you require any further assistance, we’re happy to help.

    If you found this information useful, kindly mark this as "Accept Answer".


1 additional answer

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.