Beispiel #1
0
        private void HitTesting(Point hitPoint)
        {
            bool hitConnectorFlag = false;

            DependencyObject hitObject = this.uiElement.InputHitTest(hitPoint) as DependencyObject;
            while (hitObject != null && hitObject.GetType() != typeof(Canvas))
            {
                if (hitObject is BarCode)
                {
                    selectedBarCode = hitObject as BarCode;
                    return;
                }
                hitObject = VisualTreeHelper.GetParent(hitObject);
            }
            selectedBarCode = null;
        }
Beispiel #2
0
        private void HitTesting(Point hitPoint)
        {
            bool hitConnectorFlag = false;

            DependencyObject hitObject = this.uiElement.InputHitTest(hitPoint) as DependencyObject;

            while (hitObject != null && hitObject.GetType() != typeof(Canvas))
            {
                if (hitObject is BarCode)
                {
                    selectedBarCode = hitObject as BarCode;
                    return;
                }
                hitObject = VisualTreeHelper.GetParent(hitObject);
            }
            selectedBarCode = null;
        }
Beispiel #3
0
        private void mainCanvas_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (selectedButton == null) return;
            if (selectedButton.Name == "btnBarcode")
            {
                BarCode barCode = new BarCode("1234567");
                selectedElement = barCode;
            }
            else if (selectedButton.Name == "btnText")
            {
                TextBlock tb = new TextBlock();
                tb.Text = "1234567";
                selectedElement = tb;
            }
            else if (selectedButton.Name == "btnRect")
            {
                Rectangle rectangle = new Rectangle();
                rectangle.Height = 50;
                rectangle.Width = 100;
                rectangle.Fill = Brushes.Red;
                selectedElement = rectangle;
            }
            else if (selectedButton.Name == "btnLine")
            {
                Line line = new Line();
                //line.Height = 1;
                //line.Width = 100;
                line.X1 = 10;
                line.X2 = 110;
                line.Y1 = 20;
                line.Y2 = 20;
                line.StrokeThickness = 2;
                line.Stroke = Brushes.Black;
                line.HorizontalAlignment = HorizontalAlignment.Left;
                line.VerticalAlignment = VerticalAlignment.Center;
                selectedElement = line;
            }
            else if (selectedButton.Name == "btnImg")
            {
                Image img = new Image();
                img.Width = 100;
                img.Height = 100;
                BitmapImage bitmap = new BitmapImage();
                bitmap.BeginInit();
                bitmap.UriSource = new Uri("../../../icons/barcode.png", UriKind.Relative);
                bitmap.EndInit();
                img.Source = bitmap;
                img.Stretch = Stretch.Fill;
                selectedElement = img;
            }
            mainCanvas.Children.Add(selectedElement);
            if (selectedElement.GetType() != typeof(BarCode))
            {
                selectedElement.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(selectedElement_PreviewMouseLeftButtonDown);
                selectedElement.PreviewMouseMove += new MouseEventHandler(selectedElement_PreviewMouseMove);
                selectedElement.PreviewMouseLeftButtonUp += new MouseButtonEventHandler(selectedElement_PreviewMouseLeftButtonUp);
            }
            Canvas.SetTop(selectedElement, e.GetPosition(this.mainCanvas).Y);
            Canvas.SetLeft(selectedElement, e.GetPosition(this.mainCanvas).X);

            selectedButton = null;
        }