Profile Picture

changing the bckplanestyle of a selected shape

Posted By Richard Dubé 4 Months Ago
Author
Message
Richard Dubé
Posted 4 Months Ago
View Quick Profile
Forum Newbie

Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)

Group: Forum Members
Last Active: Yesterday @ 8:04 AM
Posts: 5, Visits: 47
Hi, 
i cant figure out how i can do it with a button. I can change almost everything but the backplanestyle seems to change on all shapes.

here's the code i got

foreach (NShape shape in nDrawingView1.Selection.Nodes)
    {  
      if (shape.Style == null && shape.Style.StrokeStyle == null)
      {       
      }
      else
      {
       shape.Text = "A";
       shape.Style.EndArrowheadStyle = new NArrowheadStyle(ArrowheadShape.Arrow, "", new NSizeL(5, 5), new NColorFillStyle(Color.Gray), new NStrokeStyle(1, Color.Black));
       shape.Style.StartArrowheadStyle = new NArrowheadStyle(ArrowheadShape.Arrow, "", new NSizeL(5, 5), new NColorFillStyle(Color.Gray), new NStrokeStyle(1, Color.Black));
       shape.Style.FillStyle = new NColorFillStyle(Color.Transparent);
       NTextStyle textStyle = new NTextStyle();
 
       if (shape.Style != null && shape.Style.TextStyle != null)
       {
        textStyle = shape.Style.TextStyle;
       }
       else
       {
        textStyle = shape.ComposeTextStyle();
        NStyle.SetTextStyle(shape, textStyle);
       }
       textStyle.FontStyle = new NFontStyle("Verdana", 10, FontStyle.Regular | FontStyle.Regular);
       textStyle.FillStyle = new NColorFillStyle(Color.Black);
       textStyle.BackplaneStyle.Visible = true;
       textStyle.BackplaneStyle.StandardFrameStyle.Visible = false;
      }
    }

i tried with this  but it's not working
shape.Style.TextStyle.BackplaneStyle.Visible = true;
shape.Style.TextStyle.BackplaneStyle.StandardFrameStyle.Visible = false;

Can someone give me a hint on this please ?

Nevron Support Team
Posted 4 Months Ago
View Quick Profile
Supreme Being

Supreme Being (3,273 reputation)Supreme Being (3,273 reputation)Supreme Being (3,273 reputation)Supreme Being (3,273 reputation)Supreme Being (3,273 reputation)Supreme Being (3,273 reputation)Supreme Being (3,273 reputation)Supreme Being (3,273 reputation)Supreme Being (3,273 reputation)

Group: Moderators
Last Active: Yesterday @ 8:33 AM
Posts: 2,593, Visits: 2,279
Hi,

The problem with your code is that when you use the ComposeTextStyle method for a shape that does not have a shape style, then you get a reference to the document text style. You then modify this reference and that is why the text style of all shapes that do not have a local text style specified changes. You should clone the composed text style to avoid this. The following is a code example:

// Loop through all selected shapes
NNodeList nodes = view.Selection.Nodes;
for (int i = 0; i < nodes.Count; i++)
{
    NShape shape = nodes[i] as NShape;
    if (shape == null)
        continue;

    // Get or compose shape's text style
    NTextStyle textStyle;
    if (shape.Style != null && shape.Style.TextStyle != null)
    {
        // The shape has text style, so use it
        textStyle = shape.Style.TextStyle;
    }
    else
    {
        // The shape does not have text style, so compose it and clone it
        textStyle = (NTextStyle)shape.ComposeTextStyle().Clone();
    }

    // Create and set backplane style
    NBackplaneStyle backplaneStyle = new NBackplaneStyle();
    backplaneStyle.Visible = true;
    backplaneStyle.FillStyle = new NColorFillStyle(Color.Yellow);
    textStyle.BackplaneStyle = backplaneStyle;

    // Set shape text style
    NStyle.SetTextStyle(shape, textStyle);
}



Best Regards,
Nevron Support Team



Richard Dubé
Posted 4 Months Ago
View Quick Profile
Forum Newbie

Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)

Group: Forum Members
Last Active: Yesterday @ 8:04 AM
Posts: 5, Visits: 47
thank you for the explanation !

exaclty what i need, it work like a charm Smile



Similar Topics


Reading This Topic