728x90
반응형
728x170
■ 항상 WindowsFormsHost 엘리먼트의 속성을 사용하여 호스팅된 컨트롤에서 레이아웃 관련 속성을 설정하도록 한다. 호스팅된 컨트롤에서 직접 레이아웃 속성을 설정하면 의도하지 않은 결과가 발생한다.
▶ 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"
xmlns:winform="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
Width="800"
Height="600"
Title="TestProject"
FontFamily="나눔고딕코딩"
FontSize="16">
<Grid
Margin="10"
ShowGridLines="true">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Canvas Grid.Row="1" Grid.Column="1">
<WindowsFormsHost
Width="160"
Height="50"
Background="Yellow">
<winform:Button x:Name="button"
BackColor="Green"
FlatStyle="Flat"
Text="Click me" />
</WindowsFormsHost>
</Canvas>
</Grid>
</Window>
▶ MainWindow.xaml.cs
using System;
using System.Windows;
namespace TestProject
{
/// <summary>
/// 메인 윈도우
/// </summary>
public partial class MainWindow : Window
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainWindow()
/// <summary>
/// 생성자
/// </summary>
public MainWindow()
{
InitializeComponent();
this.button.Click += button_Click;
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
#region 버튼 클릭시 처리하기 - button_Click(sender, e)
/// <summary>
/// 버튼 클릭시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void button_Click(object sender, EventArgs e)
{
System.Windows.Forms.Button button = sender as System.Windows.Forms.Button;
button.Top = 20;
button.Left = 20;
}
#endregion
}
}
728x90
반응형
그리드형(광고전용)
'C# > WPF' 카테고리의 다른 글
[C#/WPF] WindowsFormsHost 엘리먼트 : 회전 설정하기 (0) | 2022.12.29 |
---|---|
[C#/WPF] WindowsFormsHost 엘리먼트 : 스케일링 설정하기 (0) | 2022.12.29 |
[C#/WPF] WindowsFormsHost 엘리먼트 : Visibility 속성 사용하기 (0) | 2022.12.29 |
[C#/WPF] WindowsFormsHost 엘리먼트 : 도킹 설정하기 (0) | 2022.12.29 |
[C#/WPF] WindowsFormsHost 엘리먼트 : Z 순서 제한 이해하기 (0) | 2022.12.29 |
[C#/WPF] WindowsFormsHost 엘리먼트 : Width/Height 속성을 사용해 명시적으로 크기 설정하기 (0) | 2022.12.29 |
[C#/WPF] WindowsFormsHost 엘리먼트 : 절대 위치 지정 사용하기 (0) | 2022.12.29 |
[C#/WPF] WindowsFormsHost 엘리먼트 : FontSize 속성을 사용해 컨텐츠 크기 설정하기 (0) | 2022.12.29 |
[C#/WPF] WindowsFormsHost 엘리먼트 : 기본 레이아웃 사용하기 (0) | 2022.12.29 |
[C#/WPF] WindowsFormsHost 클래스 : 하이브리드 애플리케이션에서 시각적 스타일 활성화하기 (0) | 2022.12.28 |
댓글을 달아 주세요