==> Program.cs



using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace MyWinForms
{
    static class Program
    {
        /// <summary>
        /// 해당 응용 프로그램의 주 진입점입니다.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Controls.FrmCheckedListBox());
        }
    }
}



==============================================================================================



==> MainForm.cs


        // 체크리스트 박스 관련
        private void miCheckedListBox_Click(object sender, EventArgs e)
        {
            // 생성과 동시에 오픈
            (new MyWinForms.Controls.FrmCheckedListBox()).Show();
        }


==============================================================================================



==> FrmCheckedListBox.cs



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MyWinForms.Controls
{
    public partial class FrmCheckedListBox : Form
    {
        public FrmCheckedListBox()
        {
            InitializeComponent();
        }

        private void FrmCheckedListBox_Load(object sender, EventArgs e)
        {
            string[] fav = {"C#", "ASP.NET", "WPF", "Silverlight" };

            for (int i = 0; i < fav.Length; i++)
            {
                // 짝수만 체크된 상태
                if (i % 2 != 0)
                {
                    lstFavorites.Items.Add(fav[i], true);
                }
                else
                {
                    lstFavorites.Items.Add(fav[i]);
                }
            }
        }

        private void btnSelect_Click(object sender, EventArgs e)
        {
            // Input
            List<Favorite> lst = new List<Favorite>();
            string msg = "";
            // Process
            for (int i = 0; i < lstFavorites.CheckedItems.Count; i++)
            {
                lst.Add(new Favorite()
                {
                    Name = lstFavorites.CheckedItems[i].ToString()
                });
                msg += lstFavorites.CheckedItems[i].ToString();
            }
            // Output
            ctlSelectedList.DataSource = lst; // 배열, 컬렉션, 리스트를 출력할 수 있다.
            MessageBox.Show(msg);
        }
    }

    public class Favorite
    {
        public string Name { get; set; }
    }
}





<  실행결과 >






--> '선택'버튼을 누르면 '체크리스트박스'에 체크된 항목이 'MassageBox'와 'DataGridView'에 출력됨.





Posted by holland14
:


==> MainForm.cs [디자인]



폼의 메뉴bar에서 "도움말" 메뉴 마우스오른쪽 클릭 --> "삽입" --> "MenuItem"클릭하여 메뉴항목 하나 추가하고 이름을 "창(&W)"으로 지정 --> "창" 메뉴에서 "창 닫기", "계단식 정렬", "수평 바둑판 정렬", "수직 바둑판 정렬" 항목추가하고 각 항목마다 이벤트 속성에서 "클릭" 속성 설정.


==============================================================================================



==> MainForm.cs



// 창 메뉴 관련
        private void miWindowClose_Click(object sender, EventArgs e)
        {
            Form frm = ActiveMdiChild; // 현재 열려있는 폼 가져오기
            if (frm != null)
            {
                frm.Close(); // 닫기
            }
        }

        private void miWindowCascade_Click(object sender, EventArgs e)
        {
            this.LayoutMdi(MdiLayout.Cascade); // 계단식
        }

        private void miWindowHorizontal_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileHorizontal); // 수평 바둑판
        }

        private void miWindowVertical_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileVertical); // 수직 바둑판
        }



< 실행결과 >






==> '계단식 정렬' 실행




==> '수평 바둑판 정렬' 실행




==> '수직 바둑판 정렬' 실행




Posted by holland14
:


==> MainForm.cs



        // 초간단 웹브라우저
        private void miExplorer_Click(object sender, EventArgs e)
        {
            FrmExplorer ie = new FrmExplorer();
            ie.Show();
        }



==============================================================================================



==> FrmExplorer.cs



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MyWinForms.Sample
{
    public partial class FrmExplorer : Form
    {
        public FrmExplorer()
        {
            InitializeComponent();
        }

        // 뒤로, 앞으로, 이동, 멈춤을 클릭시 모두 현재 이벤트핸들러로
        private void cmdCommon(object sender, EventArgs e) //[1]첫번째 모양 --> 예전스타일
        {
            ToolStripButton btn1 = (ToolStripButton)sender;
            if (btn1 == btnBack)
            {
                webBrowser1.GoBack(); // 뒤로
            }

            // 위 코드와 동일한 방법이다.
            ToolStripButton btn2 = sender as ToolStripButton; //[2]두번째 모양 --> 요즘 더 많이 쓰이는 방식
            if (btn2 == btnForward)
            {
                webBrowser1.GoForward(); // 앞으로
            }
            else if (btn2 == btnGo)
            {
                webBrowser1.Navigate(txtUrl.Text); // URL받아서 이동
            }
            else
            {
                webBrowser1.Stop(); // 멈춤
            }
        }
    }
}




< 실행결과 >







==> 텍스트박스에 검색URL입력 후 "이동"버튼 클릭.





==> 해당 URL로 이동.







Posted by holland14
:


==> NotifyIcon 기능 추가하기(트레이에 있는 작은 아이콘 관련기능)

1. MainForm.cs [디자인]에서 도구상자에서 'NotifyIcon'을 폼에 추가 --> 내 컴퓨터에 있는 "*.ico"파일을 검색하여 하나를 선택해서 "복사"하여 '솔루션 탐색기'의 MyWinForms에 "붙여넣기"하면 '*.ico'파일이 만들어짐. 속성의 "Icon"에서 복사한 'ico'파일의 경로로 설정해 줌.(그러면 해당아이콘이 속성창에서 보임.) 'NotifyIcon1'의 속성에서 'Name'은 '마이윈폼'으로 'BalloonTipText(풍선도움말)'과 'BalloonTipTitle'도 "마이윈폼"으로 바꿈. --> 속성에서 'ContextMenuStrip'을 'contextMenuStrip1'으로 변경한다.(-> 해당아이콘에 마우스 오른쪽버튼을 클릭하면 "프로그램 정보 / 끝내기" 컨텍스트메뉴스트립'이 뜬다. )


< 실행결과 >




==> Statusbar 트레이에 아이콘이 생성되었다.
  





==============================================================================================




==> StatusLabel(레이블로 텍스트 작성)을 추가하여 Statusbar에 "텍스트"와 "시간(Timer)"이 보이도록 만듦.

1. MainForm의 StatusStrip 클릭 --> 속성 'Items'의 (컬렉션) 클릭 --> 항목 컬렉션 편집기 --> 'StatusLabel' 3개 추가 --> 첫번째 toolStripStatusLabel1의 'Text' 속성에 '작성자 : 제시카'로 입력.

2. 두번째 toolStripStatusLabel2(공백으로 만드는 칸)에서는 'Text' 속성에 아무것도 입력하지 않고 'Spring'속성을 True로 하였다.( true로 바꾸면 첫번째와 세번째의 'toolStripStatusLabel'의 상태변화(텍스트가 늘어나거나 줄어듬)에 따라 같이 줄어들거나 늘어나게 된다. )

3. 세번째 'toolStripStatusLabel3'은 속성에서 'Name'을 sslTime로, TextAlign은 MiddleRight로 하였다.

4. 도구상자 '구성요소'에서 "Timer"를 폼으로 드래그 & 드롭 --> "timer1"의 속성에서 'Enable -> true'로
Interval -> 1000으로 변경(1초)  --> '이벤트'속성에서 'Tick -> timer1_Tick'으로 설정. --> 'timer1_Tick'더블클릭 --> Timer소스코딩하기.

5. 소스코딩

==> MainForm.cs


 private void timer1_Tick(object sender, EventArgs e)
        {
            // 스테이터스바의 3번째 레이블에 현재 시간 출력
            sslTime.Text = String.Format("{0}시 {1:0#}분 {2:0#}초",
                                DateTime.Now.Hour
                                    , DateTime.Now.Minute
                                        , DateTime.Now.Second.ToString().PadLeft(2, '0'));
        }




< 실행결과 >









Posted by holland14
:


==> Program.cs



using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace 급여처리프로그램
{
    static class Program
    {
        /// <summary>
        /// 해당 응용 프로그램의 주 진입점입니다.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
}



==============================================================================================



==> Money.cs



using System;

namespace 급여처리프로그램
{
    // 엔터티 클래스
    public class Money
    {
        public int 사번 { get; set; }
        public int 급 { get; set; }
        public int 호 { get; set; }
        public int 수당 { get; set; }
        public int 지급액 { get; set; }
        public int 세금 { get; set; }
        public int 차인지급액 { get; set; }
    }
}



==============================================================================================



==> Form1.cs



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace 급여처리프로그램
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        List<Money> money = new List<Money>(); // DB
        private bool IsOnlyNum(int 사번) {
            bool result = false;
            for (int i = 0; i < money.Count; i++) {
                if (money[i].사번 == 사번) {
                    result = true;
                }
            }
            return result;
        }
        private void btn입력_Click(object sender, EventArgs e) {
            Money m = new Money();
            if (!Char.IsDigit(txt사번.Text, 0))
            {
                MessageBox.Show("사번은 정수라니까???"); return;
            }
            // 중복 제거
            if (!IsOnlyNum(Convert.ToInt32(txt사번.Text))) {
                m.사번 = Convert.ToInt32(txt사번.Text); 
            }
            else {
                MessageBox.Show("이미 있는 사원입니다.");
                txt사번.Focus(); txt사번.Select();
                return;
            }

            m.급 = Convert.ToInt32(cbo급.Items[
                cbo급.SelectedIndex].ToString().Substring(0, 1));
            m.호 = Convert.ToInt32(com호.Items[
                com호.SelectedIndex].ToString().Substring(0, 1));
            m.수당 = Convert.ToInt32(txt수당.Text);

            money.Add(m); // 하나씩 추가

            ClearText();
            this.txt사번.Focus();
        }

        private void ClearText()
        {
            txt사번.Text = txt수당.Text = "";
            cbo급.SelectedIndex = 0;
            com호.SelectedIndex = 0;
        }

        private void cmd출력_Click(object sender, EventArgs e)
        {
            // Process
            ProcessData();

            // Sort
            IEnumerable<Money> q = (from m in money
                                   orderby m.사번
                                   select m).ToList();

            // 입력 데이터 출력
            this.dgvPrint.DataSource = q;
        }

        private void ProcessData()
        {
            for (int i = 0; i < money.Count; i++)
            {
                // 지급액 : 급 호봉 계산표
                money[i].지급액 =
                    Calc지급액(money[i].급, money[i].호) + money[i].수당;
                // 세금
                money[i].세금 = Calc세금(money[i].지급액);
                // 차인지급액
                money[i].차인지급액 = money[i].지급액 - money[i].세금;
            }
        }

        private int Calc세금(int 지급액)
        {
            int tax = 0;

            if (지급액 < 70000)
            {
                tax = (지급액 * 0) - 0;
            }
            else if (지급액 < 80000)
            {
                tax = Convert.ToInt32(지급액 * 0.005) - 300;
            }
            else if (지급액 < 90000)
            {
                tax = Convert.ToInt32(지급액 * 0.007) - 500;
            }
            else
            {
                tax = Convert.ToInt32(지급액 * 0.012) - 1000;
            }

            return tax;
        }
        private int Calc지급액(int 급, int 호)
        {
            int result = 0;
            if (급 == 1)
            {
                switch (호)
                {
                    case 1: result = 95000; break;
                    case 2: result = 92000; break;
                    case 3: result = 89000; break;
                    case 4: result = 86000; break;
                    case 5: result = 83000; break;
                    default:
                        break;
                }
            }
            else
            {
                switch (호)
                {
                    case 1: result = 80000; break;
                    case 2: result = 75000; break;
                    case 3: result = 70000; break;
                    case 4: result = 65000; break;
                    case 5: result = 60000; break;
                    default:
                        break;
                }
            }
            return result;
        }
    }
}





< 실행결과 >




--> '사원번호', '급', '호', '수당'은 입력으로 받고 '지급액', '세금', '차인지급액' 부분은 출력하면 나온다.




--> '사원번호', '급', '호', '수당'을 아래와 같이 입력한 후 출력버튼을 누른 후 화면




--> 출력 버튼을 누른 후 화면 ('지급액', '세금', '차인지급액' 부분이 출력되었다. 입력한 '사원번호', '급', '호', '수당' 도 함께 나온다.)



Posted by holland14
:


==> 증감연산자


using System;

public class 증감연산자
{
    public static void Main()
    {
        int a = 3;
        int b = 5;
        int c = 7;

        int d = ++a - --b * c--;

        Console.WriteLine("{0}", d);
    }
}


==============================================================================================


==> 시프트연산자


using System;

public class 시프트연산자
{
    public static void Main()
    {
        int a = 40;
        int r = 0;

        r = a >> 3; // 40 * 1/8(1/2의 3승)
        Console.WriteLine(r); //?

        r = a << 1; // 40 * 2(2의 1승)
        Console.WriteLine(r); //?
    }
}

/*
어떤 수를 2배 하는 코드가 필요하다?
a = a * 2;
a *= 2;
a <<= 1 ; 속도 가장빠르다.
*/


==============================================================================================


==> 비트연산자


using System;

public class 비트연산자
{
    public static void Main()
    {
        int a = 3;
        int b = 2;

        Console.WriteLine(a & b); // 비트 AND (논리곱) ==> 둘 다 참일 때만 참, 곱하기
        Console.WriteLine(a | b); // 비트 OR (논리합) ==> 하나라도 참이면 참, 더하기
        Console.WriteLine(a ^ b); // 비트 XOR (배타적논리합) ==> 서로 다를 때(배타적)만 참
        Console.WriteLine(~a); // 비트 NOT (부정) ==> 참이면 거짓, 거짓이면 참
    }
}

/*
음수 이진수 : 2의 보수법 : 부호를 붙이고 1을 더함
*/


==============================================================================================


==> 선택정렬


using System;

public class 선택정렬
{
    public static void Main()
    {
        int[] data = { 3, 5, 1, 2, 4 };

        // Process
        for (int i = 0; i < data.Length - 1; i++)
       {
                for (int j = i + 1; j < data.Length; j++)
               {
                    if (data[i] > data[j])
                   {
                        Swap(ref data[i], ref data[j]);
                   }
               }
       }
        for (int i = 0; i < data.Length; i++)
       {
            Console.WriteLine("{0}", data[i]);
       }
    }
    private static void Swap(ref int i, ref int j)
    {
        int temp = i; i = j; j = temp;
    }
}


==============================================================================================


==> 이진검색





==============================================================================================


/*

배수의 합
선택정렬 : 코드를 외워라~

이진검색 : 의미만~

*/

Posted by holland14
:

C# 콘솔 파트 관련 단어/카테고리 정리


C# 문법
절차지향 프로그래밍
1. 기본구조
2. 입출력문
3. DataType / Variable / Constant
4. Operators
5. Statements
6. Array
7. Function/Sub Procedure/Sub Routine(Method)
8. Struct / Enumeration
9. Class(BuiltIn)


개체지향 프로그래밍
1. Class : 자동차 설계도
     a. Main Method : Entry Point
     b. Field : 자동차 부품
     c. Method : 자동차 동작
     d. Constructor : 조립/시동걸기
     e. Destructor : 폐차/주차(요원)
     f. Property : 색상/크기/모양/...
     g. Indexer : 카탈로그
     h. Delegate : 대리운전(다중메서드호출)
     i. Event : 사고(메서드 수행결과)
     j. Attribute : 자동차 튜닝
2. Namespace : 자동차 브랜드
3. Interface : 자동차 설계 표준


객체지향 관련 용어
Inheritance : 상속
     super/base/parent클래스의 기능을 sub/derived/child 클래스에 상속
Encapsulation : 캡슐화
     필드를 꽁꽁 숨겨라… Field는 무조건 private
     외부에 공개시 public한 Property로 공개
Override : 오버라이드
     부모의 멤버를 자식에서 재 정의
Overload : 오버로드
     메서드 다중 정의, 동일한 이름의 메서드를 여러 개 선언
Abstraction : 추상화
     부모 클래스에는 멤버명만 정의하고 실제 구현은 자식에서
Instance : 인스턴스
     클래스로부터 개체를 생성해나가는 단계
Polymorphism : 다형성
     동일 개체를 호출하는 관점에 따라서 다른 일 수행
     부모 클래스의 인스턴스 호출시와 자식 클래스의 인스턴스 호출시 다름
     오버라이드 == 다형성
Sealed Class : 봉인 클래스
     더 이상 상속되지 않는 클래스, 최종 클래스
Object Class : 최상위 클래스
     C#에서의 최상위 클래스, 시조(?) 클래스
Access Modifiers : 접근 한정자
     private(전용) : this 내에서만 공개
     protected(제한적인 허용) : 자식에게만 공개
     public(공용) : 모두에게 멤버 공개
     internal(어셈블리) : DLL 파일내의 모든 멤버에게 공개
     protected internal(제한적인DLL) : DLL에서의 상속관계에서만…
Static과 Instance
     Static : 정적 접근, 클래스로부터 객체를 생성하지 않고, 바로 사용
     Instance : 메모리에 객체를 올린 후 사용, new 키워드 사용


알고리즘
1. SUM, COUNT, AVG
2. MAX, MIN
3. RANK
4. MODE
5. NEAR
6. SORT
     a. Selection Sort
          i. 작은것은 왼쪽
     b. Bubble Sort
          i. 인접한 데이터 비교
     c. Quick Sort
7. SEARCH / Binary Search
8. MERGE
9. GROUP


자료구조
1. STACK : LIFO
     a. 스택 Pointer(sp)
     b. Overflow : 스택이 꽉 찼을 때
     c. Underflow : 비어있을 때...
     d. 스택 Size : 스택의 크기
     e. 접시 쌓는 모양
2. QUEUE : FIFO
     a. 대기행렬, 인쇄대기, 은행 줄서기
3. LINKED LIST : LIFO+FIFO
     a. 배열보다 느리다.
     b. 삽입과 삭제가 용이하다. Add(), Remove()
4. TREE
     a. 이진 탐색 트리 : 작은게 왼쪽/아래
5. GRAPH
     a. 서울에서 부산까지 최적경로 따질 때
6. HASHTABLE
     a. 키(Key)와 값(Value)의 쌍으로 데이터 저장
     b. 충돌이 발생할 수 있다.
          i. Hash["a"] = 1234;
          ii. Hash["aa"] = 5678; // a 도 5678 덮어씀

'.NET프로그래밍 > C# 3.5 SP1' 카테고리의 다른 글

120. DLL파일만들기  (0) 2009.09.01
수업 복습(코드 실습) ==> 테스트관련 예제  (0) 2009.08.26
105. 파일처리  (0) 2009.08.24
90. 프로젝션  (0) 2009.08.20
(테스트) 체중 관리 프로그램  (0) 2009.08.20
Posted by holland14
:


==> 텍스트파일저장.cs



using System;
using System.IO; // 파일처리

public class 텍스트파일저장
{
    public static void Main()
    {
        string data = "안녕하세요.\r\n반갑습니다.";

        // StreamWriter 클래스
        StreamWriter sw = new StreamWriter("C:\\Temp\\Test.txt");

        // Write() 메서드 : 저장
        sw.WriteLine(data);

        // StreamWrite 개체를 생성했으면 반드시 닫기
        sw.Close();

        // 메모리 해제
        sw.Dispose();
    }
}




==============================================================================================



==> 텍스트파일읽기.cs



using System;
using System.IO; // 파일처리

public class 텍스트파일읽기
{
    public static void Main()
    {
        StreamReader sr = new StreamReader(@"C:\Temp\Test.txt");
        Console.WriteLine("{0}", sr.ReadToEnd()); // 전체 읽어오기
        sr.Close();
        sr.Dispose();
    }
}



==============================================================================================



==> 파일정보얻기.cs



using System;
using System.IO; //

public class 파일정보얻기
{
    public static void Main()
    {
        string file = "C:\\Temp\\Test.txt";

        // File 클래스 : 정적
        if (File.Exists(file)) // 파일이 있다면
        {
            Console.WriteLine("{0}", File.GetCreationTime(file));
            File.Copy(file, "C:\\Temp\\Test2.txt", true);
        }

        // FileInfo 클래스 : 인스턴스
        FileInfo fi = new FileInfo(file);
        if (fi.Exists) // 파일이 존재한다면,
        {
            Console.WriteLine("{0}", fi.FullName); // 파일명 출력
            // ... ===파일 관련 모든 처리 가능===
        }

    }
}




==============================================================================================



==> 폴더정보얻기.cs



using System;
using System.IO;

public class 폴더정보얻기
{
    public static void Main()
    {
        string dir = "D:\\";

        // Directory 클래스
        if (Directory.Exists(dir))
        {
            // D드라이브의 모든 폴더 목록을 출력
            foreach (string folder in Directory.GetDirectories(dir))
            {
                Console.WriteLine("{0}", folder);
            }
        }

        // DirectoryInfo 클래스
        DirectoryInfo di = new DirectoryInfo(dir + "Temp\\");
        if (di.Exists)
        {
            // D드라이브의 Temp 폴더의 모든 파일 목록 출력
            foreach (var item in di.GetFiles())
            {
                Console.WriteLine("{0}", item);
            }
        }
    }
}

Posted by holland14
:


==> MainForm.cs



        // 초간단 노트패드
        private void miNotepad_Click(object sender, EventArgs e)
        {
            FrmNotepad fn = new FrmNotepad();
            fn.MdiParent = this;
            fn.Show();
        }




==============================================================================================



==> FrmNotepad.cs



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO; // 파일 처리

namespace MyWinForms.Sample
{
    public partial class FrmNotepad : Form
    {
        public FrmNotepad()
        {
            InitializeComponent();
        }

        private void btnOpen_Click(object sender, EventArgs e)
        {
            openFileDialog1.Filter = "텍스트파일|*.txt"; // 코드레벨 설정
            if (openFileDialog1.ShowDialog() == DialogResult.OK) {
                // 텍스트 파일 열기
                StreamReader sr = new StreamReader(
                    openFileDialog1.FileName, Encoding.Default);
                // 데이터 읽어오기
                txtNote.Text = sr.ReadToEnd(); // 텍스트 모두 열기
                // 파일 닫기
                sr.Close();
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            saveFileDialog1.Filter = "텍스트파일|*.txt";
            if (saveFileDialog1.ShowDialog() != DialogResult.Cancel) {
                StreamWriter sw = new StreamWriter(
                    saveFileDialog1.FileName, false, Encoding.Default);
                sw.Write(txtNote.Text);
                sw.Close();
            }
        }
    }
}



< 실행결과 >




--> '초간단노트패드' 클릭후 화면('파일 열기'와 '파일 저장' 버튼 아래있는 텍스트박스는 'FrmNotepad.cs [디자인]' 에서 속성을 Dock ->Bottom , Multiline -> True로 설정해 주었다.)



--> 파일형식이 "텍스트파일"인 파일만 열 때 화면("텍스트파일"로 필터링 설정했음). '파일열기'버튼을 누른 후 '텍스트파일'을 선택하여 열면 해당 텍스트파일의 텍스트(내용)이 버튼 아래있는 '텍스트박스'에 열린다. 



--> 파일형식이 "텍스트파일"인 파일만 저장할 때 화면("텍스트파일"로 필터링 설정했음). '파일열기' 및 '파일저장'버튼 아래에 있는 '텍스트박스'에 텍스트를 입력한 후 '파일저장'버튼을 누르면 '텍스트파일'로 입력한 내용이 저장된다.



Posted by holland14
:


==> MainForm.cs



        // 컨트롤 - 대화상자 - 파일 및 폴더
        private void miFileFolder_Click(object sender, EventArgs e)
        {
            MyWinForms.Controls.FrmFileFolder fff = new MyWinForms.Controls.FrmFileFolder();
            fff.MdiParent = this;
            fff.Show();
        }



==============================================================================================



==> FrmFileFolder.cs



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MyWinForms.Controls
{
    public partial class FrmFileFolder : Form
    {
        public FrmFileFolder()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK) {
                MessageBox.Show("선택한 파일 : " + openFileDialog1.FileName);
            }
        }
        private void button2_Click(object sender, EventArgs e)
        {
            if (saveFileDialog1.ShowDialog() != DialogResult.Cancel) {
                MessageBox.Show("저장할 파일 : " + saveFileDialog1.FileName);
            }
        }
        private void button3_Click(object sender, EventArgs e)
        {
            DialogResult dr = folderBrowserDialog1.ShowDialog();
            if (dr == DialogResult.OK) {
                MessageBox.Show(
                    "선택한 경로 : " + folderBrowserDialog1.SelectedPath);
            }
        }

    }
}




< 실행결과 >





--> '파일 및 폴더'를 클릭한 후 화면




--> "파일 열기"를 실행한 후 화면






--> "파일 저장"을 실행한 후 화면






--> "폴더 열기"를 실행한 후 화면





Posted by holland14
: