Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.CodeDom.Compiler;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.Linq;
- using System.Runtime.CompilerServices;
- using System.Security.Cryptography.X509Certificates;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace WindowsFormsApp1
- {
- class BoardMaker
- {
- private Button[,] Table;
- private Form Board;
- public async Task<bool> Draw(Form board)
- {
- return await Task.Run(() =>
- {
- var errors = false;
- this.Board = board;
- try
- {
- Table = new Button[10,10];
- var _worker = new BackgroundWorker();
- var _boardX = 0;
- var _boardY = 0;
- for (int x = 0; x < 10; x++)
- {
- for (int y = 0; y < 10; y++)
- {
- var temp = new Button()
- {
- Height = 20,
- Width = 20,
- Location = new Point(_boardX, _boardY),
- };
- Table[x, y] = temp;
- _boardY += 20;
- }
- _boardY = 0;
- _boardX += 20;
- }
- _worker.DoWork += DrawBoard;
- }
- catch (Exception e)
- {
- errors = true;
- }
- return errors;
- });
- }
- private void DrawBoard(object sender, DoWorkEventArgs e)
- {
- foreach (var button in Table)
- {
- Board.Controls.Add(button);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement