Lottorivit.xaml.cs 1.97 KB
Newer Older
M1888's avatar
M1888 committed
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
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.Shapes;

namespace Lottokone
{
    /// <summary>
    /// Interaction logic for Lottorivit.xaml
    /// </summary>
    public partial class Lottorivit : Window
    {
        public Lottorivit()
        {
            InitializeComponent();
            NaytaKontrollit();
        }

        public void NaytaKontrollit()
        {
            StackPanel rivit = new StackPanel();
            for (int i = 0; i < Properties.Settings.Default.Vakiorivit; i++)
            {
                StackPanel rivi = new StackPanel();
                rivi.Orientation = Orientation.Horizontal;
                rivi.Name = "spRivi{i}";
                for (int j = 0; j < 7; j++)
                {
                    TextBox tb = new TextBox();
                    tb.Style = Resources["Lottonumero"] as Style;
                    tb.TextChanged += txbChanged;
                    rivi.Children.Add(tb);
                }
                rivit.Children.Add(rivi);
            }
            grdRivit.Children.Add(rivit);
        }

        public void txbChanged(object sender, TextChangedEventArgs e)
        {
            TextBox tb = sender as TextBox;
            if(tb != null)
            {
                if(int.TryParse(tb.Text, out int result))
                {
                    if(result < 1)
                    {
                        tb.Text = "1";
                    }
                    else if (result > 40)
                    {
                        tb.Text = "40";
                    }
                }
                else
                {
                    MessageBox.Show("Syötä vain numeroita 1-40");
                }
            }
        }
    }
}