Advertisement
Guest User

Canvas

a guest
Jan 16th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.55 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15.  
  16. namespace WPF_GenesteLussen
  17. {
  18.     /// <summary>
  19.     /// Interaction logic for MainWindow.xaml
  20.     /// </summary>
  21.     public partial class MainWindow : Window
  22.     {
  23.         public MainWindow()
  24.         {
  25.             InitializeComponent();
  26.         }
  27.  
  28.         private void Button_Click(object sender, RoutedEventArgs e)
  29.         {
  30.             int Rij = Convert.ToInt32(txtRij.Text);
  31.             int Kolom = Convert.ToInt32(txtKolom.Text);
  32.             Random rand = new Random();
  33.            
  34.             cnvCan.Children.Clear();
  35.             for (int i = 0; i < Rij; i++)
  36.             {
  37.                 for (int j = 0; j < Kolom; j++)
  38.                 {
  39.                     Rectangle r = new Rectangle();
  40.                     r.Width = 20;
  41.                     r.Height = r.Width;
  42.                     r.Stroke = new SolidColorBrush(Color.FromRgb((byte)(rand.Next(255)), (byte)rand.Next(255), (byte)(rand.Next(255))));
  43.                     r.Margin = new Thickness(i * r.Height, j * r.Height, 0,0);
  44.                     r.Width = 15;
  45.                     r.Height = r.Width;
  46.                     cnvCan.Children.Add(r);
  47.  
  48.                 }
  49.             }
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement