VioletaBabel
17일 : C# 윈도우 폼 입문, 계산기 본문
WPF : 프로그래머가 사용하는 C# + 디자이너가 사용하는 XML
비주얼 스튜디오에서 WPF 앱을 만듦.
c#은 확장자가 .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 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 | //MainWindow.xaml.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace WpfApp1 { /// <summary> /// MainWindow.xaml에 대한 상호 작용 논리 /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); // } private int Result = 0; // c#은 private, public이 선언시 붙어야 함. private int temp1 = 0; private bool first = true; private int check = 4; // 4 = 모름, 0 = +, 1 = -, 2 = *, 3 = / private void Button_Click(object sender, RoutedEventArgs e) {//버튼 누르는 코드 _4theyouth.Content = "Paloalto"; MessageBox.Show(T.Text); } private void TextBox_TextChanged(object sender, TextChangedEventArgs e) { } private void Button_Click_1(object sender, RoutedEventArgs e) { if (first) { T.Text = "1"; first = false; } else T.Text += "1"; } private void Button_Click_2(object sender, RoutedEventArgs e) { if (first) { T.Text = "2"; first = false; } else T.Text += "2"; } private void Button_Click_3(object sender, RoutedEventArgs e) { if (first) { T.Text = "3"; first = false; } else T.Text += "3"; } private void Button_Click_4(object sender, RoutedEventArgs e) { if (first) { T.Text = "4"; first = false; } else T.Text += "4"; } private void Button_Click_5(object sender, RoutedEventArgs e) { if (first) { T.Text = "5"; first = false; } else T.Text += "5"; } private void Button_Click_6(object sender, RoutedEventArgs e) { if (first) { T.Text = "6"; first = false; } else T.Text += "6"; } private void Button_Click_7(object sender, RoutedEventArgs e) { if (first) { T.Text = "7"; first = false; } else T.Text += "7"; } private void Button_Click_8(object sender, RoutedEventArgs e) { if (first) { T.Text = "8"; first = false; } else T.Text += "8"; } private void Button_Click_9(object sender, RoutedEventArgs e) { if (first) { T.Text = "9"; first = false; } else T.Text += "9"; } private void Button_Click_10(object sender, RoutedEventArgs e) { if (first) { T.Text = "0"; first = false; } else T.Text += "0"; } private void Button_Click_11(object sender, RoutedEventArgs e) { switch(check) { case 4: Result = Int16.Parse(T.Text); break; case 0: Result += Int16.Parse(T.Text); T.Text = Convert.ToString(Result); break; case 1: Result -= Int16.Parse(T.Text); T.Text = Convert.ToString(Result); break; case 2: Result *= Int16.Parse(T.Text); T.Text = Convert.ToString(Result); break; case 3: Result /= Int16.Parse(T.Text); T.Text = Convert.ToString(Result); break; } check = 0; first = true; } private void Button_Click_12(object sender, RoutedEventArgs e) { switch (check) { case 4: Result = Int16.Parse(T.Text); break; case 0: Result += Int16.Parse(T.Text); T.Text = Convert.ToString(Result); break; case 1: Result -= Int16.Parse(T.Text); T.Text = Convert.ToString(Result); break; case 2: Result *= Int16.Parse(T.Text); T.Text = Convert.ToString(Result); break; case 3: Result /= Int16.Parse(T.Text); T.Text = Convert.ToString(Result); break; } check = 1; first = true; } private void Button_Click_13(object sender, RoutedEventArgs e) { switch (check) { case 4: Result = Int16.Parse(T.Text); break; case 0: Result += Int16.Parse(T.Text); T.Text = Convert.ToString(Result); break; case 1: Result -= Int16.Parse(T.Text); T.Text = Convert.ToString(Result); break; case 2: Result *= Int16.Parse(T.Text); T.Text = Convert.ToString(Result); break; case 3: Result /= Int16.Parse(T.Text); T.Text = Convert.ToString(Result); break; } check = 2; first = true; } private void Button_Click_14(object sender, RoutedEventArgs e) { switch (check) { case 4: Result = Int16.Parse(T.Text); break; case 0: Result += Int16.Parse(T.Text); T.Text = Convert.ToString(Result); break; case 1: Result -= Int16.Parse(T.Text); T.Text = Convert.ToString(Result); break; case 2: Result *= Int16.Parse(T.Text); T.Text = Convert.ToString(Result); break; case 3: Result /= Int16.Parse(T.Text); T.Text = Convert.ToString(Result); break; } check = 3; first = true; } private void Button_Click_15(object sender, RoutedEventArgs e) { switch (check) { case 4: Result = Int16.Parse(T.Text); break; case 0: Result += Int16.Parse(T.Text); T.Text = Convert.ToString(Result); break; case 1: Result -= Int16.Parse(T.Text); T.Text = Convert.ToString(Result); break; case 2: Result *= Int16.Parse(T.Text); T.Text = Convert.ToString(Result); break; case 3: Result /= Int16.Parse(T.Text); T.Text = Convert.ToString(Result); break; } check = 4; first = true; } } } | 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 | <!-- MainWindow.xaml --> <Window x:Class="WpfApp1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:WpfApp1" mc:Ignorable="d" Title="Justhis" Height="350" Width="525"> <Grid> <Label x:Name="_4theyouth" Content="Label" HorizontalAlignment="Left" Margin="194,68,0,0" VerticalAlignment="Top"/> <TextBox Name="T" HorizontalAlignment="Left" Height="23" Margin="259,72,0,0" TextWrapping="Wrap" Text="0" VerticalAlignment="Top" Width="120" TextChanged="TextBox_TextChanged"/> <Button Content="+" HorizontalAlignment="Left" Margin="384,54,0,0" VerticalAlignment="Top" Width="54" RenderTransformOrigin="0.138,-1.194" Height="41" Click="Button_Click_11"/> <Button Content="/" HorizontalAlignment="Left" Margin="384,193,0,0" VerticalAlignment="Top" Width="54" RenderTransformOrigin="0.138,-1.194" Height="41" Click="Button_Click_14"/> <Button Content="-" HorizontalAlignment="Left" Margin="384,101,0,0" VerticalAlignment="Top" Width="54" RenderTransformOrigin="0.138,-1.194" Height="41" Click="Button_Click_12"/> <Button Content="*" HorizontalAlignment="Left" Margin="384,147,0,0" VerticalAlignment="Top" Width="54" RenderTransformOrigin="0.138,-1.194" Height="41" Click="Button_Click_13"/> <Button Content="=" HorizontalAlignment="Left" Margin="384,239,0,0" VerticalAlignment="Top" Width="54" RenderTransformOrigin="0.138,-1.194" Height="41" Click="Button_Click_15"/> <Button Content="1" HorizontalAlignment="Left" Margin="207,101,0,0" VerticalAlignment="Top" Width="54" RenderTransformOrigin="0.138,-1.194" Height="41" Click="Button_Click_1"/> <Button Content="2" HorizontalAlignment="Left" Margin="266,101,0,0" VerticalAlignment="Top" Width="54" RenderTransformOrigin="0.138,-1.194" Height="41" Click="Button_Click_2"/> <Button Content="3" HorizontalAlignment="Left" Margin="325,101,0,0" VerticalAlignment="Top" Width="54" RenderTransformOrigin="0.138,-1.194" Height="41" Click="Button_Click_3"/> <Button Content="4" HorizontalAlignment="Left" Margin="207,147,0,0" VerticalAlignment="Top" Width="54" RenderTransformOrigin="0.138,-1.194" Height="41" Click="Button_Click_4"/> <Button Content="5" HorizontalAlignment="Left" Margin="266,147,0,0" VerticalAlignment="Top" Width="54" RenderTransformOrigin="0.138,-1.194" Height="41" Click="Button_Click_5"/> <Button Content="6" HorizontalAlignment="Left" Margin="325,147,0,0" VerticalAlignment="Top" Width="54" RenderTransformOrigin="0.138,-1.194" Height="41" Click="Button_Click_6"/> <Button Content="7" HorizontalAlignment="Left" Margin="207,193,0,0" VerticalAlignment="Top" Width="54" RenderTransformOrigin="0.138,-1.194" Height="41" Click="Button_Click_7"/> <Button Content="8" HorizontalAlignment="Left" Margin="266,193,0,0" VerticalAlignment="Top" Width="54" RenderTransformOrigin="0.138,-1.194" Height="41" Click="Button_Click_8"/> <Button Content="9" HorizontalAlignment="Left" Margin="325,193,0,0" VerticalAlignment="Top" Width="54" RenderTransformOrigin="0.138,-1.194" Height="41" Click="Button_Click_9"/> <Button Content="0" HorizontalAlignment="Left" Margin="266,239,0,0" VerticalAlignment="Top" Width="54" RenderTransformOrigin="0.138,-1.194" Height="41" Click="Button_Click_10"/> </Grid> </Window> | cs |
'BCA > 3. C# WPF' 카테고리의 다른 글
33. 타워디펜스에 사용한, 간단한 길 찍는 툴 (0) | 2018.05.03 |
---|---|
30. 연출용 툴 (0) | 2018.04.27 |
20일 : system.net.json (0) | 2018.03.15 |
19일 : 캔버스에 도형 그리기 (0) | 2018.03.13 |
18일 : mp3 플레이어 (0) | 2018.03.12 |
Comments