첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
본 블로그는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 블로그 콘텐츠 향상을 위해 쓰여집니다.

728x90
반응형
728x170

TestProject.zip
다운로드

▶ FileSystemInfoButton.cs

using System;
using System.Diagnostics;
using System.IO;
using System.Windows;
using System.Windows.Controls;

namespace TestProject
{
    /// <summary>
    /// 파일 시스템 정보 버튼
    /// </summary>
    public class FileSystemInfoButton : Button
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Field
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region Field

        /// <summary>
        /// 파일 시스템 정보
        /// </summary>
        private FileSystemInfo fileSystemInfo;

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - FileSystemInfoButton(fileSystemInfo)

        /// <summary>
        /// 생성자
        /// </summary>
        /// <param name="fileSystemInfo">파일 시스템 정보</param>
        public FileSystemInfoButton(FileSystemInfo fileSystemInfo)
        {
            this.fileSystemInfo = fileSystemInfo;

            Content = this.fileSystemInfo.Name;

            if(this.fileSystemInfo is DirectoryInfo)
            {
                FontWeight = FontWeights.Bold;
            }

            Margin  = new Thickness(10);
            Padding = new Thickness(5);
        }

        #endregion
        #region 생성자 - FileSystemInfoButton()

        /// <summary>
        /// 생성자
        /// </summary>
        public FileSystemInfoButton() : this(new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)))
        {
        }

        #endregion
        #region 생성자 - FileSystemInfoButton(pFileSystemInfo, strText)

        /// <summary>
        /// 생성자
        /// </summary>
        /// <param name="fileSystemInfo">파일 정보 시스템</param>
        /// <param name="text">텍스트</param>
        public FileSystemInfoButton(FileSystemInfo fileSystemInfo, string text) : this(fileSystemInfo)
        {
            Content = text;
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Protected

        #region 클릭시 처리하기 - OnClick()

        /// <summary>
        /// 클릭시 처리하기
        /// </summary>
        protected override void OnClick()
        {
            if(this.fileSystemInfo is FileInfo)
            {
                Process.Start(this.fileSystemInfo.FullName);
            }
            else if(this.fileSystemInfo is DirectoryInfo)
            {
                DirectoryInfo directoryInfo = this.fileSystemInfo as DirectoryInfo;

                Application.Current.MainWindow.Title = directoryInfo.FullName;

                Panel panel = Parent as Panel;

                panel.Children.Clear();

                if(directoryInfo.Parent != null)
                {
                    panel.Children.Add(new FileSystemInfoButton(directoryInfo.Parent, ".."));
                }

                foreach(FileSystemInfo inf in directoryInfo.GetFileSystemInfos())
                {
                    panel.Children.Add(new FileSystemInfoButton(inf));
                }
            }

            base.OnClick();
        }

        #endregion
    }
}

 

728x90

 

▶ MainWindow.cs

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace TestProject
{
    /// <summary>
    /// 메인 윈도우
    /// </summary>
    public class MainWindow : Window
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - MainWindow()

        /// <summary>
        /// 생성자
        /// </summary>
        public MainWindow()
        {
            Width      = 800;
            Height     = 600;
            Title      = "디렉토리 탐색하기";
            FontFamily = new FontFamily("나눔고딕코딩");
            FontSize   = 16;

            ScrollViewer scrollViewer = new ScrollViewer();

            Content = scrollViewer;

            WrapPanel wrapPanel = new WrapPanel();

            scrollViewer.Content = wrapPanel;

            wrapPanel.Children.Add(new FileSystemInfoButton());
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Static
        //////////////////////////////////////////////////////////////////////////////// Public

        #region 프로그램 시작하기 - Main()

        /// <summary>
        /// 프로그램 시작하기
        /// </summary>
        [STAThread]
        public static void Main()
        {
            Application application = new Application();

            application.Run(new MainWindow());
        }

        #endregion
    }
}
728x90
반응형
그리드형
Posted by 사용자 icodebroker
TAG , ,

댓글을 달아 주세요