728x90
반응형
728x170
■ Adorner 클래스를 사용하는 기본적인 방법을 보여준다.
▶ FourPointsAdorner.cs
using System.Windows;
using System.Windows.Documents;
using System.Windows.Media;
namespace TestProject
{
/// <summary>
/// 4개 포인트 어도너
/// </summary>
public class FourPointsAdorner : Adorner
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - FourPointsAdorner(uiElement)
/// <summary>
/// 생성자
/// </summary>
/// <param name="uiElement">UIElement</param>
public FourPointsAdorner(UIElement uiElement) : base(uiElement)
{
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Protected
#region 렌더링시 처리하기 - OnRender(drawingContext)
/// <summary>
/// 렌더링시 처리하기
/// </summary>
/// <param name="drawingContext">DrawingContext</param>
protected override void OnRender(DrawingContext drawingContext)
{
Rect rect = new Rect(AdornedElement.DesiredSize);
drawingContext.DrawRectangle(Brushes.Blue, null, new Rect(rect.TopLeft.X , rect.TopLeft.Y , 5, 5));
drawingContext.DrawRectangle(Brushes.Blue, null, new Rect(rect.BottomLeft.X , rect.BottomLeft.Y - 5 , 5, 5));
drawingContext.DrawRectangle(Brushes.Blue, null, new Rect(rect.TopRight.X - 5 , rect.TopRight.Y , 5, 5));
drawingContext.DrawRectangle(Brushes.Blue, null, new Rect(rect.BottomRight.X - 5, rect.BottomRight.Y - 5, 5, 5));
}
#endregion
}
}
▶ MainWindow.xaml
<Window
x:Class="TestProject.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="600"
Height="450"
Title="Adorner 클래스 사용하기">
<Grid>
<Ellipse Name="ellipse"
Width="200"
Height="200"
Stroke="Black"
StrokeThickness="10"
Fill="Yellow" />
</Grid>
</Window>
▶ MainWindow.xaml.cs
using System.Windows;
using System.Windows.Documents;
namespace TestProject
{
/// <summary>
/// 메인 윈도우
/// </summary>
public partial class MainWindow : Window
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainWindow()
/// <summary>
/// 생성자
/// </summary>
public MainWindow()
{
InitializeComponent();
Loaded += Window_Loaded;
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
#region 윈도우 로드시 처리하기 - Window_Loaded(sender, e)
/// <summary>
/// 윈도우 로드시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void Window_Loaded(object sender, RoutedEventArgs e)
{
AdornerLayer.GetAdornerLayer(this.ellipse).Add(new FourPointsAdorner(this.ellipse));
}
#endregion
}
}
728x90
반응형
그리드형(광고전용)
'C# > WPF' 카테고리의 다른 글
[C#/WPF] Visual 클래스 : TransformToAncestor 메소드를 사용해 부모 엘리먼트 기준 좌표 구하기 (0) | 2015.11.05 |
---|---|
[C#/WPF] MouseEventArgs 클래스 : GetPosition 메소드 사용하기 (0) | 2015.11.05 |
[C#/WPF] 엘리먼트를 마우스로 드래그해 이동시키기 (0) | 2015.11.05 |
[C#/WPF] FrameworkElement 클래스 : 프레임워크 엘리먼트 전면으로 보이기 (0) | 2015.11.04 |
[C#/WPF] WindowsFormsHost 클래스 : WinForm 컨트롤의 부모 WindowsFormsHost 구하기 (0) | 2015.11.04 |
[C#/WPF] Popup 클래스 : 팝업 활성화하기 (0) | 2015.11.04 |
[C#/WPF] UIElement 클래스 : JPEG 이미지 구하기 (0) | 2015.11.04 |
[C#/WPF] WindowsFormsHost 클래스 : 브라우저 애플리케이션(XBAP)에서 사용하기 (0) | 2015.11.03 |
[C#/WPF] BrowserInteropHelper 클래스 : IsBrowserHosted 정적 속성을 사용해 브라우저 애플리케이션 (XBAP) 여부 구하기 (0) | 2015.11.03 |
[C#/WPF] x:FieldModifier 속성 : 엘리먼트를 public으로 노출시키기 (0) | 2015.10.28 |
댓글을 달아 주세요