Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Changing Pen Color (Read 3631 times)
CodeLabyrinth
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 3
Joined: Apr 26th, 2017
Changing Pen Color
Apr 26th, 2017 at 9:59pm
Print Post  
Hey there,

I am using C# and I am having the problem that I can't change the pen color for only the new shapes which I want to draw. If I select a new pen color, it affects all elements, which were drawn on the diagram. I want to use different colors, so that I can distinguish between the shape elements.

I hope that you can help me  Smiley

Thanks !
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Changing Pen Color
Reply #1 - Apr 27th, 2017 at 8:27am
Print Post  
Hi,

Pen is a reference type so it sounds you have assigned a shared Pen instance to all items. E.g. when creating new nodes don't do this -

newNode.Pen = myform.DefaultPen;

but this to make sure Pen objects are different -

newNode.Pen = (Pen)myform.DefaultPen.Clone();

Then setting node.Pen.Color = new Color(...) will change it only for specific node. Alternatively keep the shared pen until you need to change the color, and assign new instance then -

node.Pen = new Pen(newColor, node.Pen.Width);

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
CodeLabyrinth
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 3
Joined: Apr 26th, 2017
Re: Changing Pen Color
Reply #2 - May 1st, 2017 at 2:59pm
Print Post  
Hey,

sorry I didn't get it exactly. I am creating the Shape elements on runtime and not progmatically.

This is for example my code:

Code
Select All
Theme theme = new Theme();
ShapeNodeStyle style = new ShapeNodeStyle();
style.Stroke = new MindFusion.Drawing.SolidBrush(colorDialog1.Color);
theme.RegisterStyle(typeof(ShapeNode), style);
diagram1.Theme = theme; 



Like I said before, if I am trying to change for example the stroke color which should only affect the new elements which I want to draw.

Thanks ! Smiley
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Changing Pen Color
Reply #3 - May 1st, 2017 at 4:44pm
Print Post  
Hi,

Okay, the stroke you assign to theme's default style for ShapeNodes is still shared among all nodes. You can either set strokes in separate ShapeNodeStyle objects assigned to node.Style, or create Pen object and assign it to node.Pen. The precedence is node.Pen > node.Style.Stroke* > Theme style. For interactively-drawn nodes you can set per-node Pen or Style from InitializeNode event handler or NodeCreated event handler, depending on whether you want the new stroke to be visible while the user still draws.

Regards,
Slavcho
« Last Edit: May 10th, 2017 at 5:26am by Slavcho »  
Back to top
 
IP Logged
 
CodeLabyrinth
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 3
Joined: Apr 26th, 2017
Re: Changing Pen Color
Reply #4 - May 9th, 2017 at 8:00pm
Print Post  
It works ! Thank you so much Cheesy Now, how can I also affect the shape which is selected ?
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Changing Pen Color
Reply #5 - May 10th, 2017 at 5:38am
Print Post  
Try this -

Code
Select All
if (diagram.ActiveItem != null)
    diagram.ActiveItem.Pen = new Pen(...); 



Regards,
Slavcho
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint