BoldDeskBoldDesk is now live on Product Hunt with a special offer: 50% off all plans. Let's grow together! Support us.
when I want to edit a text in a textnode I do the following steps:
1. look for the node. 2. Clone it. 3. Delete the original one. 4. Assign the new text. 5. Append the new node into the diagram.
This is the code that I use:
Node existeNode = f_parent.diagram1.Model.GetChildByName(nodeText.Name);
if (existeNode != null) { TextNode tn = ((TextNode)nodeText).Clone() as TextNode; f_parent.diagram1.Model.RemoveChild(((TextNode)nodeText)); tn.Text = "new text"; f_parent.diagram1.Model.AppendChild(tn); }
Is there any way to make it more simple? Without clone and delete the original node? |
Before looking into the requirement could you please provide us what is the actual intention for Cloning the original node and deleting the original node?
Since the requirement can be achieved by removing the existing node and adding the new node instead of cloning the original node.
If we misunderstand your requirement could you please provide us more information about your requirement which will help us to analyze further and provide you a better solution? |
Doing that way I have problems when the zoom of the diagram is different of 100% |
Could you please provide us more information probably a video and related files used in your application which reproduces the reported concern will help us to analyze further and provide you a better solution? |
Then I don't need to clone the node? But the name of the new node will be different, won't be? I want to edit the text of the textnode but without losing the node name, is it possible? Could you send me an example? |
We are glad to inform you that we have created a simple sample to achieve your requirement. We suggest you to remove the existing node and create a new node with respect to the existing node so that the old node is removed and new node has been created and same name has been assigned which is to be done in TextEditor_TextChanged event. Please refer the below code snippet and sample for your reference.
Here is the code snippet:
[C#]
diagram2.Controller.TextEditor.TextChanged+=TextEditor_TextChanged;
void TextEditor_TextChanged(object sender, EventArgs e) { //Removing the Existing node. this.diagram2.Model.RemoveChild(((TextNode)existeNode)); //Creation of new node. TextNode Tn2 = ((TextNode)existeNode) as TextNode; //Assigning the existing node’s name to the new node. Tn2.Name = existeNode.Name; }
Here is the Sample:
|
And I send you a video with the problem with the zoom.
|
We suggest you to update the TextNode’s font size based on the size of the node. Please refer the below code snippet and video for your reference.
Here is the code snippet:
Tn2.Text = "This is the Text Node This is the Text Node This is the Text Node This is the Text Node This is the Text Node This is the Text Node This is the Text Node This is the Text Node This is the Text Node"; Tn2.SizeToText(new SizeF(Tn2.Text.Length, Tn2.Size.Height)); Tn2.WrapText = true;
Here is the Video:
|
n2.WrapText = true;
I have tried it but the result it's the same.
if (tn.FontStyle.Size != 12)
{
tn.FontStyle.Size = 12;
}
But I think the fontsize should remain the same.
Hi Blanca,
Thanks for your update.
We are glad to inform you that we have successfully achieved your requirement by modifying the sample. We suggest you to pass “true” in diagram1.Controller.TextEditor.EndEdit’s parameter to avoid changing of font size. We have attached the modified sample, code snippet and video for your reference.
Here is the code snippet:
[C#]
diagram1.Controller.TextEditor.EndEdit(true);
Here is the modified Sample:
Sample
Here is the Video:
Video
Please let us know if any concerns.
Regards,
Swarnesh K