Different appearance for preview shape and real shape

Oct 26, 2012 at 2:48 PM

Hi,

How can I achieve different appearance for preview shape and real shape?

For example, in my real shape's Draw() method I'm drawing text + image, but in the preview shape I want to draw only text.

Oct 29, 2012 at 5:15 AM
Edited Oct 29, 2012 at 5:15 AM

I think I've found the answer:

public bool IsPreview { get; set; }

public override void MakePreview(IStyleSet styleSet)
{
    base.MakePreview(styleSet);
    this.IsPreview = true;
}

And in the Draw() method I can choose what to draw depending upon the value of the IsPreview property.

What do you think?

Coordinator
Oct 29, 2012 at 9:34 AM

The NShape way would be to assign transparent styles to the shape's privateLineStyle and FillStyle properties (the styleSet parameter is a readonly version of the Design):

public override void MakePreview(IStyleSet styleSet)
{
    base.MakePreview(styleSet);
    LineStyle = styleSet.GetPreviewStyle(styleSet.LineStyles.None);
    FillStyle = styleSet.GetPreviewStyle(styleSet.FillStyles.Transparent);
}
Oct 29, 2012 at 9:51 AM

Well, in my original question ("How can I achieve different appearance for preview shape and real shape?"), by saying "appearance" I meant not only border and interior, but other things as well. More exactly, I needed to prevent drawing image for preview shapes.

Coordinator
Oct 29, 2012 at 10:30 AM

I'm not sure what you mean with "prevent drawing image for preview shapes", but that does not really matter as there is absolutely no reason to implement a 'IsPreviewShape' path in the draw method. Assigning transparent styles is an easy way but if this is not sufficient for your purposes, feel free to implement it in the draw method.

Oct 29, 2012 at 10:49 AM

I meant the following:

public override void Draw(Graphics graphics)
{
    this.DrawSomeText();
    if(we_are_in_preview_mode == false)
        this.DrawSomeImage();
}

The problem was how to get value of "we_are_in_preview_mode". I found out that I can simply create a boolean flag in MakePreview() method override. I called this flag as "IsPreview" (see code snippet in my 2nd message).