Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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.Navigation;
- using System.Windows.Shapes;
- using System.Windows.Threading;
- namespace WpfAppOefentoets
- {
- /// <summary>
- /// Interaction logic for MainWindow.xaml
- /// </summary>
- public partial class MainWindow : Window
- {
- DispatcherTimer tmMove = new DispatcherTimer();
- bool bMoveToRight = true;
- public MainWindow()
- {
- InitializeComponent();
- tbSwap1.IsReadOnly = true;
- tbSwap2.IsReadOnly = true;
- tmMove.Interval = TimeSpan.FromMilliseconds(0.5);
- tmMove.Tick += TmMove_Tick;
- }
- private void TmMove_Tick(object sender, EventArgs e)
- {
- double xpos = btn3.Margin.Left;
- double ypos = btn3.Margin.Top;
- if (bMoveToRight == true)
- {
- xpos++;
- }
- else
- {
- xpos--;
- }
- if ( btn3.Margin.Left + btn3.ActualWidth > cC0R4.ActualWidth)
- {
- bMoveToRight = false;
- }
- if (btn3.Margin.Left < 0)
- {
- bMoveToRight = true;
- }
- btn3.Margin = new Thickness(xpos, ypos, 0, 0);
- }
- private void btnColorswap_Click(object sender, RoutedEventArgs e)
- {
- if (btnColorswap.Background == Brushes.Red)
- {
- btnColorswap.Background = Brushes.Orange;
- }
- else if (btnColorswap.Background == Brushes.Orange)
- {
- btnColorswap.Background = Brushes.Green;
- }
- else
- {
- btnColorswap.Background = Brushes.Red;
- }
- }
- private void btnSwap_Click(object sender, RoutedEventArgs e)
- {
- string sSwap = tbSwap1.Text;
- tbSwap1.Text = tbSwap2.Text;
- tbSwap2.Text = sSwap;
- }
- private void btnVerander_Click(object sender, RoutedEventArgs e)
- {
- btnVerander.Content = "zoek";
- btnVerander.IsEnabled = false;
- Random rnd = new Random();
- int iMaxWidth = Convert.ToInt32(cC0R1.ActualWidth);
- int iRandomWidthButton = rnd.Next(0, iMaxWidth);
- int iMaxHeight = Convert.ToInt32(cC0R1.ActualHeight);
- int iRandomHeightButton = rnd.Next(0, iMaxHeight);
- btnRandom.Width = iRandomWidthButton;
- btnRandom.Height = iRandomHeightButton;
- double dblX = cC0R1.ActualWidth - btnVerander.Width;
- int iX = Convert.ToInt32(dblX);
- int marginX = rnd.Next(0, iX);
- double dblY = cC0R1.ActualHeight - btnVerander.Height;
- int iY = Convert.ToInt32(dblY);
- int marginY = rnd.Next(0, iY);
- btnRandom.Margin = new Thickness(marginX, marginY, 0, 0);
- btnRandom.Visibility = Visibility.Visible;
- }
- private int a = 0;
- private void btn3_Click(object sender, RoutedEventArgs e)
- {
- a++;
- btn3.Content = a.ToString();
- btn3.Content = ("U heeft " + a + " keer geklikt.");
- }
- private void btnRandom_Click(object sender, RoutedEventArgs e)
- {
- btnVerander.Content = "Start";
- btnVerander.IsEnabled = true;
- btnRandom.Visibility = Visibility.Hidden;
- }
- private void btn3_MouseEnter(object sender, MouseEventArgs e)
- {
- tmMove.Start();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement