Exemple #1
0
        /// <summary>
        /// 在窗口 上按下左键时触发
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            Point         point  = e.GetPosition(Mytest);
            DrawingVisual visual = new DrawingVisual();

            DrawSquare(visual, point);
            Mytest.AddVisual(visual);
        }
Exemple #2
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            DrawingVisual  dv    = new DrawingVisual();
            DrawingContext dc    = dv.RenderOpen();
            Brush          brush = Brushes.Red;
            Pen            pen   = new Pen(Brushes.Green, 3);

            dc.DrawRectangle(brush, pen, new Rect(new Point(100, 100), new Size(50, 100)));
            dc.DrawEllipse(brush, pen, new Point(200, 200), 20, 100);

            dc.DrawLine(pen, new Point(0, 0), new Point(50, 50));
            dc.DrawLine(pen, new Point(50, 50), new Point(20, 50));
            dc.DrawLine(pen, new Point(20, 50), new Point(0, 0));
            dc.Close();

            Mytest.AddVisual(dv);
        }