첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

■ WindowsFormsHost 엘리먼트에서 Visibility 속성을 설정하여 Windows Forms 컨트롤을 보이지 않게 만들거나 축소할 수 있다. 컨트롤이 보이지 않으면 표시되지 않지만 레이아웃 공간을 차지한다. 컨트롤이 축소되면 표시되지 않으며 레이아웃 공간을 차지하지도 않는다.

TestProject.zip
0.01MB

▶ 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>
        <StackPanel Grid.Row="1" Grid.Column="1">
            <Button Name="invisibleButton"
                Background="OrangeRed"
                Content="Click to make invisible" />
            <WindowsFormsHost Name="host"
                Background="Yellow">
                <winform:Button
                    FlatStyle="Flat"
                    Text="Windows Forms control" />
            </WindowsFormsHost>
            <Button Name="collapseButton"
                Background="OrangeRed"
                Content="Click to collapse" />
        </StackPanel>
    </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.invisibleButton.Click += invisibleButton_Click;
            this.collapseButton.Click  += collapseButton_Click;
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region Click to make invisible 버튼 클릭시 처리하기 - invisibleButton_Click(sender, e)

        /// <summary>
        /// Click to make invisible 버튼 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void invisibleButton_Click(object sender, EventArgs e)
        {
            this.host.Visibility = Visibility.Hidden;
        }

        #endregion
        #region Click to collapse 버튼 클릭시 처리하기 - collapseButton_Click(sender, e)

        /// <summary>
        /// Click to collapse 버튼 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void collapseButton_Click(object sender, EventArgs e)
        {
            this.host.Visibility = Visibility.Collapsed;
        }

        #endregion
    }
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요