Hi, Slavcho
private void CreateNodes(string path)
{
var myImage = new BitmapImage(new Uri(path, UriKind.Relative));
var imageWidthPx = myImage.PixelWidth * GetScreenDpi() / myImage.DpiX;
var imageHeightPx = myImage.PixelHeight * GetScreenDpi() / myImage.DpiY;
var imageWidth = GraphicsUnit.Pixel.Convert(imageWidthPx, diagram.MeasureUnit);
var imageHeight = GraphicsUnit.Pixel.Convert(imageHeightPx, diagram.MeasureUnit);
imageNode = diagram.Factory.CreateShapeNode(0, 0, imageWidth, imageHeight);
imageNode.Image = myImage;
imageNode.Shape = Shapes.Rectangle;
imageNode.Locked = true;
imageNode.ImageAlign = ImageAlign.BottomRight;
double.TryParse(textBoxW.Text, out overlayNodeWidth);
double.TryParse(textBoxH.Text, out overlayNodeHeight);
var newBounds = new System.Windows.Rect(imageNode.Bounds.Right - overlayNodeWidth, imageNode.Bounds.Bottom - overlayNodeHeight, overlayNodeWidth, overlayNodeHeight);
// Change the node's position / dimensions
overlayNode.SetBounds(newBounds, true, true);
overlayNode.EnabledHandles ^= AdjustmentHandles.Move | AdjustmentHandles.BottomHandles | AdjustmentHandles.RightHandles;
zoomInMax = overlayNode.Bounds;
diagram.InvalidateForeground();
}
The above piece of code realizes the creation of two ShapeNodes in the diagram instance, imageNode and overlayNode. There are a few problems I don’t understand very well:
1. imageNode.ImageAlign = ImageAlign.BottomRight; what this code does here What is it?
2. When the overlayNode is created, it is fixed at the lower right corner of the imageNode, which is achieved by these two lines of code: double.TryParse(textBoxW.Text, out overlayNodeWidth);
double.TryParse(textBoxH.Text, out overlayNodeHeight);var newBounds = new System.Windows.Rect(imageNode.Bounds.Right-overlayNodeWidth, imageNode.Bounds.Bottom-overlayNodeHeight, overlayNodeWidth, overlayNodeHeight);overlayNode.SetBounds(newBounds, true , true); However, I change the value in the TextBox:
private void tb_PreviewTextInput(object sender, TextCompositionEventArgs e)
{
Regex re = new Regex("[^0-9]+");
e.Handled = re.IsMatch(e.Text);
}
That is, after changing the value of textBoxW or textBoxH, overlayNode is no longer fixed at the lower right corner of the imageNode, but at the upper left corner of the imageNode. Why is this happening? How can I modify the program to keep the overlayNode at the bottom right corner of the imageNode?
3. May I ask this code: overlayNode.EnabledHandles ^= AdjustmentHandles.Move | AdjustmentHandles.BottomHandles | AdjustmentHandles.RightHandles; and this code: zoomInMax = overlayNode.Bounds; What is the function?
4. How to change this regular expression to limit the value to only two decimal places?
Best regards.