Test Program for water
<Window x:Class="WATER.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" mc:Ignorable="d" Title="WATER" Height="100" Width="200"> <Grid> <Button x:Name="button" Content="FUCK THIS" HorizontalAlignment="Left" Margin="92,33,0,0" VerticalAlignment="Top" Width="92" Height="29" Click="change"/> <TextBox x:Name="textBox" Height="24" TextWrapping="Wrap" Text="100" VerticalAlignment="Top" FontSize="18" IsEnabled="False" Margin="4,4,4,0"/> <TextBox x:Name="textBox2" HorizontalAlignment="Left" Height="23" Margin="4,36,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="63.619" IsEnabled="False"/> </Grid> </Window>
using System; using System.Windows; using System.Windows.Threading; namespace WATER { /// <summary> /// MainWindow.xaml 的交互逻辑 /// </summary> public partial class MainWindow : Window { private DispatcherTimer timer; private DispatcherTimer timer2; int value = 100; int cm = 0; public MainWindow() { InitializeComponent(); Loaded += new RoutedEventHandler(Window2_Loaded); Loaded += new RoutedEventHandler(Window1_Loaded); } private void change(object sender, RoutedEventArgs e) { Random rd = new Random(); value = rd.Next(0, 100); //textBox.Text = Convert.ToString(value); /* if (value != 100) { MessageBox.Show("Only 100cm can fuck it", "Error"); value = 100; textBox.Text = Convert.ToString(value); }*/ } void Window1_Loaded(object sender, RoutedEventArgs e) { timer = new DispatcherTimer(); timer.Interval = TimeSpan.FromSeconds(3); timer.Tick += timer1_Tick; timer.Start(); } void Window2_Loaded(object sender, RoutedEventArgs e) { timer = new DispatcherTimer(); timer.Interval = TimeSpan.FromSeconds(1); timer.Tick += timer2_Tick; timer.Start(); } private void timer1_Tick(object sender, EventArgs e) { if (value != 100) { ++cm; textBox2.Text = Convert.ToString(cm + " times"); ///value = 100; //textBox.Text = Convert.ToString(value); } } private void timer2_Tick(object sender, EventArgs e) { textBox.Text = Convert.ToString(value + " cm"); } } }