올해 발표하고 많은 사람들이 업데이트한 Windows 10!

마이크로소프트의 차기 운영체제로 마이크로소프트에서도 밀고 있는 운영체제인데요 지금까지 배운 C#으로

GUI 프로그래밍을 해보겠습니다.

첫 번째로 프로젝트를 만들어 봅시다!

1. File -> New  -> Project 를 누릅니다.



2.Visual C# -> Universal -> Blank App(Universal Windows) 를 누르고 이름을 HelloWindows10 을 하고 OK를 눌러줍니다.

짠 하고 생성되었습니다 다른것들은 차차 알아갈테니 우리가 가장 중요하게 봐야 하는것!

MainPage.xaml을 클릭해줍니다


그럼 이렇게 Xaml과 Degin이 생깁니다.

우리가 중점을 두어야 할 것은 바로 이 Xaml입니다. 마이크로소프트는 처음에 C언어와 C++언어를 이용해서 윈도우즈 프로그래밍 언어를 만들게끔 도구들을 제공했습니다. 바로 Win32 API와 MFC 인데요 하지만 너무 어려웠고 비주얼 스튜디오때문에 쓴다는 말이 있을 정도로 그렇게 까지 좋지 않았습니다.

그렇게 발전하고 발전하다가 나온게 xaml이라는 마크업 언어로 디자인을 하고 C#/C++/VB로 코딩을 하는 방법을 나오게 되었고 지금 wpf->windows 8->windows 10이런식으로 발전하면서 윈도우즈 프로그래밍은 이렇게 만드는 것으로 고착화?가 된듯 합니다. 이런 배경이 궁금하신분들은 찾아보시고! 우리 Hello Windows 10을 만들어 봅시다

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<Page
    x:Class="HelloWindows10.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:HelloWindows10"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">
 
    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
 
    </Grid>
</Page>
 
cs

바로 생성된 xaml 파일! 하나하나 볼까요?

      x:Class="HelloWindows10.MainPage"

이것은 xaml 파일의 가장 중요한 루트(뿌리)에서만 나타나며 C#에 의하면 class 와 같은 의미를 가지는 것입니다 즉 HelloWindows10이라는 네임스페이스 하위의 Mainpage 클래스는 Page로부터 나타난 것이다 라고 생각하시면 됩니다.

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

2006년이 마이크로소프트가 이런 방식과 xaml을 처음으로 선보인 해 입니다. winfx라는것은 이런 방식이 wpf라고도 하는데 이렇게 발표되기 전에는 Winfx라고도 불렸다네요 그래서 winfx가 삽입되어 있습니다. xaml은 WPF,실버라이트,윈도우폰,윈도우즈 사이에서 어느정도 호환은 되지만 공통되는 것은 클래스와 속성과 기능뿐입니다.

나머지 세줄은 마이크로소프트에서 디자인과 기획툴로 사용되는 블랜드라는 툴을 위한 코드이므로 무시하셔도 됩니다!

자그럼 우리 Hello Windows 10을 만들어 볼까요?

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

    </Grid>

사이에 코드를 적어 봅시다

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<Page
    x:Class="HelloWindows10.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:HelloWindows10"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">
 
    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <TextBlock Text="Hello, Windows 10"
                   FontFamily="segoe UI"
                   FontSize="96"
                   Foreground="SkyBlue"
                   HorizontalAlignment="Center"
                   VerticalAlignment="Center" />
    </Grid>
</Page>
 
cs

1. TextBlock 글자를 보여주는 도구 입니다 그안에 여러가지 속성이 있습니다.

Text=Text="Hello, Windows 10"""  ""안에 우리가 쓰고 싶은 글자를 써주시면 됩니다

FontFamily="segoe UI"               ""안에 원하는 폰트 이름을 넣어주시면 됩니다. 저는 윈도우 공식폰트인 segoe UI

FontSize="100"                         폰트 사이즈! 저는 단순하게 100 넣어볼게요!

Foreground="SkyBlue"              색생! 저는 시원하게 Skyblue를 넣어 보겠습니다!

 HorizontalAlignment="Center"   수평으로 가운데! 라는 뜻인데요 어느 플랫폼이든 가운데에 넣을 수 있게 됩니다!

 VerticalAlignment="Center"      수직으로 가운데! 이또한 어느 플랫폼이나 기기든 가운데에 넣을수 있게 됩니다.


이렇게 나오면 잘 됮거에요!

그럼 실행해 봅시다!


우아 먼가 멋있죠? 아 뭔가 예뻐... 우리의 첫 GUI 프로그램 Hello World가 완성되었습니다.

Xaml 생각보다 어렵지 않고 신기하죠? 다음은 로또번호 생성기를 만들면서 버튼도 만들어 보겠습니다!


드디어! 까만화면에 커서만 번뜩번뜩 하던것을 떠나서

우리가 정말 쓰는 프로그램 같은 네모에 이것저것 나오는 GUI 프로그래밍을 해볼 것 입니다.

C#에서 GUI를 만들때 쓰는 방법은 WindowsForm,WPF,Universal App 이정도로 있습니다(WIndows 8 은점유율이 낮으니 제외하도록 하겠습니다)

하지만 WindowsForm은 점점 쓰지 않는 기술이고 다른 두개와 방식이 많이 다릅니다. 그래서 저는 WindowsForm은 하지 않겠습니다.

제가 주로 할 것은 Uiversal App(Windows 10) 인데요 이 방식은 Xaml 이라는 Markup 언어를 사용하고 그 방식이 비슷합니다.

최근 Microsoft에서도 밀고 있는 언어이기도 하고 Universal App을 하게 되면 WPF나 Windows 8 사용하는데 큰 지장이 없습니다.

또한 이것을 통해서 익혀 두면 Web에서 사용하는 ASP .NET을 쉽게 익히실수 있을 것 입니다.(사실 이거 두개만해도 Windows 8 app도 가능합니다)

그래서 프로젝트를 WIndows 10 Universal App을  한번 만들어 보겠습니다.

우리가 콘솔환경에서 했던것을 GUI로 한번 복습한후 다음 진도로 넘어갈게요!

그럼 다음 포스팅때 봐요~~!

자 우리 까만화면 시리즈의 마지막 행맨을 해봅시다!

제가 생각한 방법은 

1. 클래스를 하나 더 만들겠습니다! 컴퓨터 클래스를 만들어서 문제들을 몇개 넣을거에요! 배열로요!

2. 이겼습니다 졌습니다 나오는 메서드와 행맨의 상태를 보여주는 메서드를 만들겠습니다.

3. 레벨이 5이상일때 끝내는 매서드를 만들겠습니다.

4. 레벨이 5면 끝내고 아니라면 입력한 문자를 바꾸어주는 메서드를 만들겠습니다.

5. 주 클래스로 와서 String을 입력받고 그 값이 에러가 아니라면 리턴해주는 메서드를 만들겠습니다.

6. 마지막으로 While문으로 이기거나 지기까지 계속 하게 만드는 메서드를 만들겠습니다.

Computer.cs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Hangman  // 크게 입력 문제인지, 비교문제인지, 알아 보아야 함
{
    class Computer
    {
        private String[] m_key =
        {
            "Boolean",
            "Integer",
            "String",
            "System",
            "Thread",
            "StringBuffer",
            "Package",
            "Class",
            "Object",
            "Void"
        };
        public StringBuilder m_user;  //유저가 넣은 글자
        public String m_word;        // 컴퓨터가 랜덤으로 넣은 글자
        private int m_level;          // 맞거나 틀리거나 한 레벨
        private int m_index;          // 크기를 알아야 그 크기 만큼 -로 채울수 있다
        public Computer()            //생성자를 통해서 변수 초기화
        {
            Random myrand = new Random();
            m_index = myrand.Next(m_key.Length-1); //랜덤으로 값을 인덱스에 넣고 번째 찾음
            m_word = m_key[m_index];               //나의 키 중에 나의 인덱스를 가진값을 word에 넣음 예 0은 boolean
            m_level = 0;                           //레벨은 9부터 시작
 
            m_user = new StringBuilder();         //유저가 넣은 값을 stringbuilder 에 넣음
           
            
            for(int i=0;i<m_word.Length;i++)       //word에 길이 만큼 -생성
            {
                m_user.Append('_');
            }
 
        }
        public void showEndMsg(Boolean isWin) // true false값을 통해서 메세지 생성 함수
        {
            String msg;
 
            if(true == isWin)
            {
                msg = "사형수를 구하셨습니다";
            }
            else 
            {
                msg = "사형이 집행 되었습니다.";
            }
            Console.WriteLine(msg);
        }
        public void showHangMan()           //레벨을 가지고 행맨을 보여주는 함수
        {
            Console.WriteLine("★ 집행 단계 ★");
            switch (m_level)
            {
                case 0:
                    Console.WriteLine("    ┌──┐");
                    Console.WriteLine("    ▲    ┃");
                    Console.WriteLine("          ┃");
                    Console.WriteLine("          ┃");
                    Console.WriteLine("          ┃");
                    Console.WriteLine("          ┃"); ;
                    break;
                case 1:
                    Console.WriteLine("    ┌──┐");
                    Console.WriteLine("    ▲    ┃");
                    Console.WriteLine("┌─┼─  ┃");
                    Console.WriteLine("          ┃");
                    Console.WriteLine("          ┃");
                    Console.WriteLine("          ┃");
                    break;
                case 2:
                    Console.WriteLine("    ┌──┐");
                    Console.WriteLine("    ▲    ┃");
                    Console.WriteLine("┌─┼─┐┃");
                    Console.WriteLine("          ┃");
                    Console.WriteLine("          ┃");
                    Console.WriteLine("          ┃");
                    break;
                case 3:
                    Console.WriteLine("    ┌──┐");
                    Console.WriteLine("    ▲    ┃");
                    Console.WriteLine("┌─┼─┐┃");
                    Console.WriteLine("    ┃    ┃");
                    Console.WriteLine("          ┃");
                    Console.WriteLine("          ┃");
                    break;
                case 4:
                    Console.WriteLine("    ┌──┐");
                    Console.WriteLine("    ▲    ┃");
                    Console.WriteLine("┌─┼─┐┃");
                    Console.WriteLine("    ┃    ┃");
                    Console.WriteLine("┌─┼─  ┃");
                    Console.WriteLine("          ┃");
                    break;
                case 5:
                    Console.WriteLine("    ┌──┐");
                    Console.WriteLine("    ▲    ┃");
                    Console.WriteLine("┌─┼─┐┃");
                    Console.WriteLine("    ┃    ┃");
                    Console.WriteLine("┌─┼─┐┃");
                    Console.WriteLine("          ┃");
                    break;
                default:
                    Console.WriteLine("  ┌───┐");
                    Console.WriteLine("      ┃");
                    Console.WriteLine("      ┃");
                    Console.WriteLine("      ┃");
                    Console.WriteLine("      ┃");
                    Console.WriteLine("      ┃");
                    break;
 
            }
        }
        private int checkEnd()              
        {
            String t_msg;
 
            t_msg = m_user.ToString();
            
            if(t_msg.Equals(m_key[m_index]))
            {
                return 1;
            }
 
            if(5<=m_level)
            {
                return 2;
            }
            return 0;
        }
        public int checkLevel(char msg)
        {
            Boolean find = false;
 
            for(int i =0;i<m_key[m_index].Length;i++)
            {
                if(m_key[m_index][i]==msg)
                {
                    if('_' == m_user[i]) //중복을 막아준다
                    {
                        m_user[i]=msg;
                        find = true;
                        break;
                    }
                }
            }
            if(false == find)
            {
                m_level++;
            }
            return checkEnd();
        }
    }
}
 
cs

Program.cs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Hangman
{
    class Program
    {
        Computer m_com;
        public void Hangman()
        {
            m_com = new Computer();
        }
        public char getKey()
        {
            String msg;
 
            char a;
            msg = "error";
         
            Console.WriteLine("알파벳을 입력하세요:");
            msg = Console.ReadLine();
         
            a = msg[0];
            return a;
        }
        public void run()
        {
            int result;
            char msg;
 
            while (true)
            {
                Console.WriteLine(" "+m_com.m_user);
                msg = getKey();
                result = m_com.checkLevel(msg);
 
                m_com.showHangMan();
                if(1==result)
                {
                    m_com.showEndMsg(true);
                    break;
                }
                else if(2==result)
                {
                    m_com.showEndMsg(false);
                    break;
                }
            }
           
 
        }
        static void Main(string[] args)
        {
            Program m = new Program();
            m.Hangman();
            m.run(); 
        }
    }
}
 
cs
프로그램 모습




+ Recent posts