우리 로또 번호을 universal app으로 만들어 봅시다
먼저 로또번호가 나와야할 Textblock이 하나 필요하겠네요
두번째 로는 버튼이 필요할 것 같네요 버튼을 누를때 마다 새로운 로또 번호를 생성하도록 만들어 보겠습니다
첫번째로는 xaml 파일로 버튼과 텍스트 블록을 만들어 줍니다. 위치나 크기 등등은 마음대로 해보세요
이렇게 위치도 바꾸어 보고 만져보면서 xaml에 더 나아가 윈도우앱에 익숙해집니다!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <Page x:Class="uniappTest.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:uniappTest" 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}" Margin="0,0,-647,0"> <Button x:Name="button" Content="로또 번호 생성하기" HorizontalAlignment="Left" Margin="675,188,0,0" VerticalAlignment="Top" Click="button_Click"/> <TextBlock x:Name="textBlock" HorizontalAlignment="Left" Margin="148,188,0,0" TextWrapping="Wrap" Text="로또 번호 생성기" VerticalAlignment="Top" Width="522" Height="32"/> </Grid> </Page> | 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 | using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.InteropServices.WindowsRuntime; using Windows.Foundation; using Windows.Foundation.Collections; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Controls.Primitives; using Windows.UI.Xaml.Data; using Windows.UI.Xaml.Input; using Windows.UI.Xaml.Media; using Windows.UI.Xaml.Navigation; // The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409 namespace uniappTest { /// <summary> /// An empty page that can be used on its own or navigated to within a Frame. /// </summary> public sealed partial class MainPage : Page { int[] number; Random my_rand; public MainPage() { number = new int[7]; my_rand = new Random(); this.InitializeComponent(); } private void button_Click(object sender, RoutedEventArgs e) { MakeNumber(); textBlock.Text = " "; // 초기화 전에 있던 거 지우기 for (int i = 0; i < number.Length;i++) { if (number.Length-1==i) { textBlock.Text += " 보너스 번호는 " + number[number.Length - 1]; } else { textBlock.Text += " " + number[i]; } } } void MakeNumber() { int a; for (int i = 0; i < number.Length; i++) { a = my_rand.Next(1, 45); if (true == CheckSame(i, a)) { number[i] = a; } else { i--; } } } bool CheckSame(int index,int value) { for (int i = 0; i < index; i++) { if (value == number[i]) { return false; } } return true; } } } | cs |
나머지는 앞에서 콘솔로 만들었던 것과 같습니다! 조금 달랐던점은 제가 주석으로 표시를 해두었으니 참고하시면서
꼭 자기손으로 만들어 보시길 바랍니다!
실행화면
'Visual C# > Universal App' 카테고리의 다른 글
17. C#/Xaml Windows 10 app 강좌 가위바위보!(1) 알아두어야 할 것들 (0) | 2015.11.22 |
---|---|
15. C#/Xaml Windows 10 app 강좌 Hello, Windows 10 (0) | 2015.10.28 |
14. C# 강좌 GUI 프로그래밍을 하기전에 (0) | 2015.10.25 |
13. C# 강좌 행맨 Hangman (2) (0) | 2015.10.24 |
12. C# 강좌 행맨 Hangman (1) 알아야 할 것들 (0) | 2015.10.24 |