Font

Hi,
How to change Font at TextNode which have arranged on the diagramme.
How to appoint keys Ctrl + '+' and Ctrl + '-' for scaling diagramm.
In advance thanks.


3 Replies

J. J.Nagarajan Syncfusion Team August 14, 2008 12:53 PM UTC

Hi ,

1. Change Font of TextNode:

You can use FontStyle property of the TextNode and you can change the font at run time. Please refer to the below code snippet.

Syncfusion.Windows.Forms.Diagram.TextNode txtnode = new TextNode( "SIMPLE FLOW DIAGRAM" );
txtnode.FontStyle.Size = 20;
txtnode.FontStyle.Italic = true;
txtnode.FontStyle.Bold = true;
txtnode.FontStyle.Family = "Cambria";
txtnode.FontColorStyle.Color = Color.Purple;
txtnode.LineStyle.LineColor = Color.Transparent;
txtnode.SizeToText(SizeF.Empty);
txtnode.PinPoint = new PointF(250, 30);
this.diagram1.Model.AppendChild(txtnode);

2. To appoint keys Ctrl + '+' and Ctrl + '-' for scaling diagram:

For scaling the diagram, you have to derive the ZoomTool and override the ProcessMouseUp() method. To catch the Ctrl + '+' and Ctrl+ '-' key, you have to override ProcessCmdKey() method. Please refer to the below code snippet.

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
this.diagram1.Focus();
if (diagram1.ContainsFocus)
{

if (((keyData & Keys.Control) == Keys.Control) && ((keyData & Keys.Oemplus) == Keys.Oemplus))
{
zoomTool = new CustomZoomTool(this.diagram1.Controller);
this.diagram1.Controller.RegisterTool(zoomTool);
this.diagram1.Controller.ActivateTool(zoomTool);
zoomTool.SingleActionTool = false;
zoomTool.ProcessMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 1, 1, 1));
}
if (((keyData & Keys.Control) == Keys.Control) && ((keyData & Keys.OemMinus) == Keys.OemMinus))
{
if (zoomTool != null)
zoomTool.ProcessMouseUp(new MouseEventArgs(MouseButtons.Right, 0, 0, 1, 1));
}

}
return base.ProcessCmdKey(ref msg, keyData);
}

Here is the working sample.

http://websamples.syncfusion.com/samples/Diagram.Windows/F75907/main.htm

Please refer to it and let me know if this helps.

Regards,
Nagaraj



SE Segey August 15, 2008 05:58 AM UTC

Thanks for the answer. And if I create TextNode in separate class TextField. How to address to it for font change.
In advance thanks.



J. J.Nagarajan Syncfusion Team August 18, 2008 11:57 AM UTC

Hi ,

You can derive a TextNode in a separate class and you can set the font to that TextNode. Please refer to the below code snippet.

class TextField:TextNode
{
public TextField(string Text):base(Text)
{
this.FontStyle.Size = 20;
this.FontStyle.Italic = true;
this.FontStyle.Bold = true;
this.FontStyle.Family = "Cambria";
this.FontColorStyle.Color = Color.Purple;
this.LineStyle.LineColor = Color.Transparent;
this.SizeToText(SizeF.Empty);
this.PinPoint = new PointF(250, 30);
}
}

//To Add TextField to the Diagram Model

TextField m_txtField = new TextField("SIMPLE FLOW DIAGRAM");
this.diagram1.Model.AppendChild(m_txtField);

Please refer to the attached sample for more details.

http://websamples.syncfusion.com/samples/Diagram.Windows/F75907_Aug18/main.htm

Please let me know if this helps.

Thanks,
Nagaraj



Loader.
Up arrow icon