■ Canvas 클래스의 SetLeft/SetTop 메소드를 사용해 엘리먼트의 좌상단 좌표를 설정하는 방법을 보여준다.
▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
using System.Windows.Controls; using System.Windows.Media; using System.Windows.Shapes; Canvas canvas = new Canvas(); Rectangle rectangle = new Rectangle(); rectangle.Width = 200; rectangle.Height = 200; rectangle.Stroke = Brushes.Black; rectangle.StrokeThickness = 3; rectangle.Fill = Brushes.Blue; Canvas.SetLeft(rectangle, 100); Canvas.SetTop (rectangle, 100); canvas.Children.Add(rectangle); |