We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Edit text in a textnode

Thread ID:

Created:

Updated:

Platform:

Replies:

119581 Jul 10,2015 03:08 AM Jul 23,2015 12:36 AM Windows Forms 11
loading
Tags: Diagram
Blanca Calderon
Asked On July 10, 2015 03:08 AM

Hi,

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? Doing that way I have problems when the zoom of the diagram is different of 100%

Thanks in advanced
            

        
    
           

Swarnesh Krishna Kumar [Syncfusion]
Replied On July 13, 2015 03:00 AM

Hi Blanca,
Thanks for using syncfusion products.

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?


Please let us know if any concerns.
Regards,
Swarnesh K

Blanca Calderon
Replied On July 13, 2015 03:15 AM

Hi,

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?

And I send you a video with the problem with the zoom. 



Attachment: Video_1436778515_34b68200.zip

Swarnesh Krishna Kumar [Syncfusion]
Replied On July 14, 2015 05:17 AM

Hi Blanca,
Thanks for your update.

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:


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:


Video


Please let us know if any concerns.
Regards,
Swarnesh K

Blanca Calderon
Replied On July 15, 2015 05:50 AM

Sorry but it doesn't work. 

If I don't use clone the textnode text doesn't change. And If I use clone option,  works but the zoom doesn't work. 

In the video that I send you doesn't appear:

Tn2.SizeToText(new SizeF(Tn2.Text.Length, Tn2.Size.Height));

n2.WrapText = true;


I have tried it but the result it's the same.


Attachment: Video_1436960644_5f686131.zip

Naganathan Ganesh Babu [Syncfusion]
Replied On July 16, 2015 08:46 AM

Hi Blanca,
 
Thanks for your update.
 
We have created a simple sample to achieve your requirement. We suggest you to use TextEditor’s “EndEdit” method and pass the parameter as false in order to achieve your requirement. Please refer the below code snippet and sample for your references.
 
Here is the code snippet:
[C#]
diagram1.Controller.TextEditor.EndEdit(false);
 
Here is the video:
Video
 
Here is the sample:
Sample
 
Please let us know if any concerns.
 
Regards,
 
Naganathan K G

Blanca Calderon
Replied On July 17, 2015 01:47 AM

Ok,

diagram1.Controller.TextEditor.EndEdit(false); works fine but the problem with the zoom it is different.

If the magnification is different from 100%, the fontsize of the node changes (eg. zoom 250%, fontsize=30.0), always bigger that the original size, 12.
 I don't know why the Font size of the textnode changes but it happens.

Using this code avoid the problem:

if (tn.FontStyle.Size != 12)

{

tn.FontStyle.Size = 12;

}

But I think the fontsize should remain the same.


 
 

Swarnesh Krishna Kumar [Syncfusion]
Replied On July 20, 2015 08:53 AM

Hi Blanca,
Thanks for your patience.
We are able to reproduce the issue reported by you at our end. We have forwarded this to our development team for further analysis. We will update you with our development team’s response in one business day 21st July 2015.
Please let us know if any concerns.
Regards,
Swarnesh K

Blanca Calderon
Replied On July 21, 2015 02:55 AM

Ok, thank you so much.

Swarnesh Krishna Kumar [Syncfusion]
Replied On July 21, 2015 04:58 AM

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


Blanca Calderon
Replied On July 21, 2015 05:05 AM

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


Yes, this time yes, thank you!

Naganathan Ganesh Babu [Syncfusion]
Replied On July 23, 2015 12:36 AM

Hi Blanca,
Thanks for your update.
We are happy to assist you and please let us know if you need any further assistance.
Regards,
Naganathan K G

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;