17,741
社区成员
发帖
与我相关
我的任务
分享
bool controll = false;
DispatcherTimer timer;
Random random;
public MainWindow()
{
InitializeComponent();
timer = new DispatcherTimer();
random = new Random();
timer.Interval = new TimeSpan(0,0,5);
timer.Tick += Timer_Tick;
}
private void Timer_Tick(object sender, EventArgs e)
{
Window_Main.Background = new SolidColorBrush(Color.FromRgb(BitConverter.GetBytes(random.Next(0, 255))[0], BitConverter.GetBytes(random.Next(0, 255))[0], BitConverter.GetBytes(random.Next(0, 255))[0]));
}
private void Btn_Start_Click(object sender, RoutedEventArgs e)
{
if (!controll)
{
timer.Start();
Btn_Start.Content = "Stop";
}
else
{
timer.Stop();
Btn_Start.Content = "Start";
}
}