D wrote on Mar 19
th, 2020 at 1:35am:
I think like the crosshairs in this picture, when I drag the image in ShapeNode with the mouse, the ruler moves, the crosshairs don't move with the ruler, and even stay at the horizontal and vertical midpoints of the diagram. How does this work? Is there any sample code?
The crossharis drawing code from the above post puts them in the center of the document bounds. If you want to draw them always at the 0,0 point, change the mx and my variables in the DrawForeground handler to 0, like this:
var mx = 0; //(r.Left + r.Right) / 2;
var my = 0; //(r.Top + r.Bottom) / 2;
D wrote on Mar 19
th, 2020 at 2:06am:
How to use the value of two TextBoxes to control the width and height of the ShapeNode in the diagram? Is there any sample code?
D wrote on Mar 19
th, 2020 at 2:26am:
I want to input the X and Y coordinates of the upper left corner of the two TextBoxes to control the position of the image on the ShapeNode. Is there any sample code?
Just assign a numeric value from a TextBox to a Rect x, y, width, height value respectively and set that Rect as the selected node's bounds. For example:
private void Button_Click(object sender, RoutedEventArgs e)
{
// Check for selected node
var node = diagram.ActiveItem as ShapeNode;
if (node == null)
return;
double x = node.Bounds.X,
y = node.Bounds.Y,
w = node.Bounds.Width,
h = node.Bounds.Height;
// Get the new values from the 4 text boxes
double newValue;
if (double.TryParse(textBoxX.Text, out newValue))
x = newValue;
if (double.TryParse(textBoxY.Text, out newValue))
y = newValue;
if (double.TryParse(textBoxW.Text, out newValue))
w = newValue;
if (double.TryParse(textBoxH.Text, out newValue))
h = newValue;
// Change the node's position / dimensions
node.SetBounds(new Rect(x, y, w, h), true, true);
}
Regards,
Lyubo,
MindFusion