Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Figure out how the diagram is instantiated in the cs code (Read 3019 times)
JackPan
Full Member
***
Offline


I Love MindFusion!

Posts: 134
Joined: Apr 9th, 2020
Figure out how the diagram is instantiated in the cs code
Apr 15th, 2020 at 2:07am
Print Post  
Hi All,

I tried to change the length and width of the overlayNode with the TextBox's TextChanged event, but an error occurred while running, indicating that the diagram did not seem to be instantiated.
cs:
        private void textBoxW_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (overlayNode == null)
            {
                if (double.TryParse((((TextBox)sender).Text), out overlayNodeHeight))
                {
                    if (((TextBox)sender).Text != overlayNodeHeight.ToString())
                    {
                        ((TextBox)sender).Text = overlayNodeHeight.ToString();
                        ((TextBox)sender).SelectionStart = overlayNodeHeight.ToString().Length;
                    }
                }
                var newBounds = new Rect(0, 0, overlayNodeWidth, overlayNodeHeight);
                overlayNode = diagram.Factory.CreateShapeNode(newBounds);
                diagram.InvalidateForeground();
            }
        }

        private void textBoxH_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (overlayNode == null)
            {
                if (double.TryParse((((TextBox)sender).Text), out overlayNodeHeight))
                {
                    if (((TextBox)sender).Text != overlayNodeHeight.ToString())
                    {
                        ((TextBox)sender).Text = overlayNodeHeight.ToString();
                        ((TextBox)sender).SelectionStart = overlayNodeHeight.ToString().Length;
                    }
                }
                var newBounds = new Rect(0, 0, overlayNodeWidth, overlayNodeHeight);
                overlayNode = diagram.Factory.CreateShapeNode(newBounds);
                diagram.InvalidateForeground();
            }
        }

Any assistance would be appreciated.

Cheers,

JackPan
  

4_15_1.png (Attachment deleted)
Back to top
 
IP Logged
 
Lyubo
God Member
*****
Offline


MindFusion team

Posts: 511
Joined: Jun 17th, 2010
Re: Figure out how the diagram is instantiated in the cs code
Reply #1 - Apr 15th, 2020 at 6:52am
Print Post  
Hi,

The problem must be included in the exception details, but can't read it to help you out since it's not in English. From the small details you've posted, this looks more like the overlayNodeWidth variable might be null, if it's not been instantiated when the textBoxW_TextChanged handler is called for the first time.

On a side note, this approach looks flawed as it does not do what you indicate you are trying to do. The current code will run only once (even if it didn't crash), because overlayNode will no longer be null after it's done.

Create your node from a Window.Loaded event, and use the TextBox.TextChanged events only to change the size.

Regards,
Lyubo
MindFusion
  
Back to top
 
IP Logged
 
JackPan
Full Member
***
Offline


I Love MindFusion!

Posts: 134
Joined: Apr 9th, 2020
Re: Figure out how the diagram is instantiated in the cs code
Reply #2 - Apr 15th, 2020 at 8:08am
Print Post  
Yes, you're right. Lyubo.

Indeed, as you said, this method looks flawed because it does not follow my instructions.
I currently want to make the TextBox input the value, the mouse focus leaves the current TextBox will change the length or width of the overlayNode, use two TextBox to complete this operation to change the length and width of the overlayNode. What method is used to achieve it?

Any assistance would be appreciated.

Cheers,

JackPan
  
Back to top
 
IP Logged
 
Lyubo
God Member
*****
Offline


MindFusion team

Posts: 511
Joined: Jun 17th, 2010
Re: Figure out how the diagram is instantiated in the cs code
Reply #3 - Apr 15th, 2020 at 11:49am
Print Post  
  
Back to top
 
IP Logged
 
JackPan
Full Member
***
Offline


I Love MindFusion!

Posts: 134
Joined: Apr 9th, 2020
Re: Figure out how the diagram is instantiated in the cs code
Reply #4 - Apr 15th, 2020 at 1:36pm
Print Post  
Yes, I used the method inside to achieve it.

Thank you, Lyubo. Smiley

Cheers,

Jack
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint