Advertisement
isotonicq

Untitled

Apr 18th, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.98 KB | None | 0 0
  1. using System;
  2. using System.CodeDom.Compiler;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Runtime.CompilerServices;
  8. using System.Security.Cryptography.X509Certificates;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12.  
  13. namespace WindowsFormsApp1
  14. {
  15.     class BoardMaker
  16.     {
  17.         private Button[,] Table;
  18.         private Form Board;
  19.         public async Task<bool> Draw(Form board)
  20.         {
  21.             return await Task.Run(() =>
  22.              {
  23.                  var errors = false;
  24.                  this.Board = board;
  25.  
  26.                  try
  27.                  {
  28.                      Table = new Button[10,10];
  29.                      var _worker = new BackgroundWorker();
  30.                      var _boardX = 0;
  31.                      var _boardY = 0;
  32.  
  33.                      for (int x = 0; x < 10; x++)
  34.                      {
  35.                          for (int y = 0; y < 10; y++)
  36.                          {
  37.                              var temp = new Button()
  38.                              {
  39.                                  Height = 20,
  40.                                  Width = 20,
  41.                                  Location = new Point(_boardX, _boardY),
  42.                              };
  43.  
  44.                              Table[x, y] = temp;
  45.  
  46.                              _boardY += 20;
  47.                          }
  48.                          _boardY = 0;
  49.                          _boardX += 20;
  50.                      }
  51.  
  52.                      _worker.DoWork += DrawBoard;
  53.                  }
  54.                  catch (Exception e)
  55.                  {
  56.                      errors = true;
  57.                  }
  58.  
  59.                  return errors;
  60.              });
  61.         }
  62.  
  63.         private void DrawBoard(object sender, DoWorkEventArgs e)
  64.         {
  65.             foreach (var button in Table)
  66.             {
  67.                 Board.Controls.Add(button);
  68.             }
  69.         }
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement