Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Application of setting the size of ShapeNode in different events (Read 1636 times)
JackPan
Full Member
***
Offline


I Love MindFusion!

Posts: 134
Joined: Apr 9th, 2020
Application of setting the size of ShapeNode in different events
Sep 21st, 2020 at 1:40am
Print Post  
Hi, there. Smiley

I want to change the value of textBoxW or change the value of textBoxH in the TextChanged event to change the width or height of the overlayNode, but when this code is executed, an error will be reported:
I want to change the value of textBoxW or change the value of textBoxH in the TextChanged event to change the width or height of the overlayNode, but when this code is executed, an error will be reported:
var newBounds = new System.Windows.Rect(imageNode.Bounds.Right-overlayNodeWidth , imageNode.Bounds.Bottom-overlayNodeHeight, overlayNodeWidth, overlayNodeHeight);
The error content is: System.NullReferenceException: "The object reference was not set to the instance of the object."
Message=The object reference is not set to the instance of the object.
[Call stack has been truncated]
But this code appears in the textBoxW_PreviewMouseMove event, there is no problem. May I ask why this happens?
The error content is: System.NullReferenceException: "The object reference was not set to the instance of the object."
Message=The object reference is not set to the instance of the object.
[Call stack has been truncated]
But this code appears in the textBoxW_PreviewMouseMove event, there is no problem. May I ask why this happens?
private void textBoxW_PreviewMouseMove(object sender, MouseEventArgs e)
        {
            if (isDragging)
            {
                //double newValue;
                System.Windows.Point p = e.GetPosition(this);
                if (p.X > clickPoint.X)
                {
                    if (double.TryParse(textBoxW.Text, out newValueW))
                        newValueW += 0.1;
                    if (double.TryParse(textBoxH.Text, out newValueH))
                    {
                        var newBounds = new System.Windows.Rect(imageNode.Bounds.Right - newValueW, imageNode.Bounds.Bottom - newValueH,
                                        newValueW, newValueH);
                        // Change the node's position / dimensions
                        overlayNode.SetBounds(newBounds, true, true);
                        textBoxW.Text = newValueW.ToString();
                    }
                }
                else if (p.X < clickPoint.X)
                {
                    if (double.TryParse(textBoxW.Text, out newValueW))
                        newValueW -= 0.1;
                    if (double.TryParse(textBoxH.Text, out newValueH))
                    {
                        var newBounds = new System.Windows.Rect(imageNode.Bounds.Right - newValueW, imageNode.Bounds.Bottom - newValueH,
                                        newValueW, newValueH);
                        // Change the node's position / dimensions
                        overlayNode.SetBounds(newBounds, true, true);
                        textBoxW.Text = newValueW.ToString();
                    }
                }
                else
                    base.OnPreviewMouseMove(e);
            }
            diagram.InvalidateForeground();
        }

Any assistance would be appreciated.

Cheers,

Jack
  

9_21_1.png ( 128 KB | 92 Downloads )
9_21_1.png
9_21_2.png ( 131 KB | 97 Downloads )
9_21_2.png
9_21_3.png ( 171 KB | 104 Downloads )
9_21_3.png
Back to top
 
IP Logged
 
Lyubo
God Member
*****
Offline


MindFusion team

Posts: 511
Joined: Jun 17th, 2010
Re: Application of setting the size of ShapeNode in different events
Reply #1 - Sep 21st, 2020 at 4:56am
Print Post  
Hi,

Is it imageNode that is null? Can't tell from the picture. Make sure that it or the variable that gives you the error is not null when this code runs or null check at the beginning of the method.

Code
Select All
//...
if (imageNode == null)
    return;
//... 

\

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


I Love MindFusion!

Posts: 134
Joined: Apr 9th, 2020
Re: Application of setting the size of ShapeNode in different events
Reply #2 - Sep 21st, 2020 at 5:38am
Print Post  
Thanks very much, Lyubo Smiley

Best regards. Smiley Smiley Smiley
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint