Window_NumPad.xaml.cs 3.93 KB
Newer Older
潘栩锋's avatar
潘栩锋 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 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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;
using System.ComponentModel;

namespace FLY.UI.OSK
{
    /// <summary>
    /// Window_NumPad.xaml 的交互逻辑
    /// </summary>
    public partial class Window_NumPad : Window, INotifyPropertyChanged
    {
        private System.Windows.Threading.DispatcherTimer timer;
        private TextBox textbox = null;


        public Window_NumPad()
        {
            InitializeComponent();

            timer = new System.Windows.Threading.DispatcherTimer();

            timer.Interval = TimeSpan.FromSeconds(0.1);
            timer.Tick += new EventHandler(timer_Tick);
        }
        void timer_Tick(object sender, EventArgs e)
        {
            timer.Stop();
            this.ShowDialog();
        }
        public void Open(TextBox textbox)
        {

            this.textbox = textbox;
            this.Result = textbox.Text;
            
            timer.Start();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            this.textblock_result.DataContext = this;
        }
        private void button_7_Click(object sender, RoutedEventArgs e)
        {
            Result += "7";
        }

        private void button_8_Click(object sender, RoutedEventArgs e)
        {
            Result += "8";
        }

        private void button_9_Click(object sender, RoutedEventArgs e)
        {
            Result += "9";
        }

        private void button_4_Click(object sender, RoutedEventArgs e)
        {
            Result += "4";
        }

        private void button_5_Click(object sender, RoutedEventArgs e)
        {
            Result += "5";
        }

        private void button_6_Click(object sender, RoutedEventArgs e)
        {
            Result += "6";
        }

        private void button_1_Click(object sender, RoutedEventArgs e)
        {
            Result += "1";
        }

        private void button_2_Click(object sender, RoutedEventArgs e)
        {
            Result += "2";
        }

        private void button_3_Click(object sender, RoutedEventArgs e)
        {
            Result += "3";
        }

        private void button_backspace_Click(object sender, RoutedEventArgs e)
        {
            Result = "";
        }

        private void button_close_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void button_enter_Click(object sender, RoutedEventArgs e)
        {
            if (this.textbox != null)
            {
                this.textbox.Text = Result;
            }
            this.Close();
        }

        private void button_symbol_Click(object sender, RoutedEventArgs e)
        {
            Result += "-";
        }

        private void button_0_Click(object sender, RoutedEventArgs e)
        {
            Result += "0";
        }

        private void button_pot_Click(object sender, RoutedEventArgs e)
        {
            Result += ".";
        }

        string result;

        public string Result
        {
            get { return result; }
            set
            {
                if (result != value)
                {
                    result = value;
                    NotifyPropertyChanged("Result");
                }
            }
        }


        protected void NotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        public event PropertyChangedEventHandler PropertyChanged;

        private void Border_MouseDown(object sender, MouseButtonEventArgs e)
        {
            this.DragMove();
        }
    }
}