Example #1
0
        private async Task sendFieldToMainFormAsync(LField field, int step1, int step2)
        {
            Task tsk = Task.Run(() =>
            {
                field.Location = new Point(step1 * (field.Width) + 10, step2 * (field.Height) + 10);
                //_fieldsContainer[step1, step2] = field;
            }

                                );
            await tsk;
        }
Example #2
0
 public async Task initialiseMatrix()
 {
     for (int i = 0; i < _fieldsContainer.GetLength(0); i++)
     {
         for (int j = 0; j < _fieldsContainer.GetLength(1); j++)
         {
             _fieldsContainer[i, j] = new LField(FieldSize);
             await sendFieldToMainFormAsync(_fieldsContainer[i, j], i, j);
         }
     }
     exportFieldsNow?.Invoke(_fieldsContainer);
 }
        private async void initilizeMainCanvas()
        {
            this.Width       = Screen.PrimaryScreen.Bounds.Width;
            this.WindowState = FormWindowState.Maximized;



            pnlFieldsHolder.Width  = (this.Width - this.Width / 5) - 20;
            pnlFieldsHolder.Height = Screen.PrimaryScreen.Bounds.Height - 100;

            if (pnlFieldsHolder.Height < pnlFieldsHolder.Width)
            {
                pnlFieldsHolder.Width = pnlFieldsHolder.Height;
            }

            pnlFieldsHolder.Location = new Point(this.Width - pnlFieldsHolder.Width - 10, 10);
            pnlFieldsHolder.drawBorder(1, Color.Black);

            this.Controls.Add(pnlFieldsHolder);


            int numberOfFields = (pnlFieldsHolder.Height - pnlFieldsHolder.Height / 25) / this.FieldSize;

            _currentBoard           = new Canvas(numberOfFields * numberOfFields);
            _currentBoard.FieldSize = this.FieldSize;


            _currentBoard.exportFieldsNow += async(LField[,] fields) =>
            {
                Task tsk = Task.Run(() =>
                {
                    _localContainer = fields;

                    LField[] plainContainer = new LField[fields.Length];
                    int count = 0;
                    foreach (var s in fields)
                    {
                        plainContainer[count] = s;
                        count++;
                    }

                    if (pnlFieldsHolder.InvokeRequired)
                    {
                        pnlFieldsHolder.Invoke((Action) delegate { pnlFieldsHolder.Controls.AddRange(plainContainer); });
                    }
                    else
                    {
                        pnlFieldsHolder.Controls.AddRange(plainContainer);
                    }

                    initialisePreviewAndSave(pnlFieldsHolder.Location);
                }
                                    );

                await tsk;
            };


            initialiszeColorPicker();
            await _currentBoard.initialiseMatrix();
        }