728x90
728x170
▶ 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="800"
Height="600"
Title="WindowsFormsHost 클래스 : WinForm 객체 사용시 스크롤 영역 클리핑 처리하기"
FontFamily="나눔고딕코딩"
FontSize="16">
<Border Margin="20" BorderThickness="1" BorderBrush="Black">
<ScrollViewer>
<StackPanel Name="stackPanel" />
</ScrollViewer>
</Border>
</Window>
728x90
▶ MainWindow.xaml.cs
using System;
using System.Windows;
using System.Windows.Controls;
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)
{
System.Drawing.Color[] colorArray = new System.Drawing.Color[]
{
System.Drawing.Color.Red,
System.Drawing.Color.Green,
System.Drawing.Color.Blue
};
for(int i = 0; i < 100; i++)
{
ScrollableWindowsFormsHost host = new ScrollableWindowsFormsHost();
host.Width = 100;
host.Height = 100;
host.Margin = new Thickness(10);
System.Windows.Forms.UserControl control = new System.Windows.Forms.UserControl();
control.BackColor = colorArray[i % 3];
host.Child = control;
this.stackPanel.Children.Add(host);
}
}
#endregion
}
}
300x250
▶ WindowsFormsHost.cs
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Forms.Integration;
using System.Windows.Media;
using System.Windows.Controls;
/// <summary>
/// 스크롤 가능한 윈도우 폼 호스트
/// </summary>
728x90
그리드형(광고전용)
'C# > WPF' 카테고리의 다른 글
[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 |
[C#/WPF] 객체 동적 바인딩 처리하기 (0) | 2015.10.22 |
[C#/WPF] WPF Window의 소유자를 WinForm Form으로 설정하기 (0) | 2015.10.22 |
[C#/WPF] DrawingBrush 엘리먼트 : EllipseGeometry 객체의 크기를 변경해 애니메이션 만들기 (0) | 2015.10.21 |
[C#/WPF] VisualBrush 엘리먼트 : RelativeTransform 속성을 사용해 엘리먼트 반사 이미지 만들기 (0) | 2015.10.20 |
[C#/WPF] ImageBrush 엘리먼트 : TileMode 속성을 FlipXY로 설정하기 (0) | 2015.10.20 |
[C#/WPF] ImageBrush 엘리먼트 : ViewboxUnits 속성 사용하기 (0) | 2015.10.20 |