private void submitButton_Click(object sender, EventArgs e)
        {
            messageBoxForm childForm = new messageBoxForm();

            if (nameTextbox.Text == "")
            {
                GlobalVars.MessageBoxPassedVar = "EmptyName";
                childForm.ShowDialog();
                return;
            }
            else if (noRadioButton.Checked && imageLocationLabel.Text == "")
            {
                GlobalVars.MessageBoxPassedVar = "ChooseImageIfNoChecked";
                childForm.ShowDialog();
                return;
            }
            else if (imageLocationLabel.Text != "" && yesRadioButton.Checked)
            {
                GlobalVars.MessageBoxPassedVar = "ImageChosenButYesChecked";
                childForm.ShowDialog();
                return;
            }
            var tileChosen = mainForm.globalTileList.First(x => x.ID == GlobalVars.PropertiesPassedVar);

            tileChosen.Name            = nameTextbox.Text;
            tileChosen.ProgramLocation = programLocationLabel.Text;
            tileChosen.UseProgramIcon  = yesRadioButton.Checked;
            tileChosen.ImageLocation   = imageLocationLabel.Text;
            GlobalVars.PassedBackVar   = tileChosen;
            this.Close();
        }
Beispiel #2
0
        private void gridImage_Click(object sender, EventArgs e)
        {
            var coordinates = gridImage.PointToClient(Cursor.Position);
            int rowNum      = Convert.ToInt32(Math.Floor((decimal)coordinates.Y / 100));
            int colNum      = Convert.ToInt32(Math.Floor((decimal)coordinates.X / 100));

            if (rowNum > 3 || colNum > 7 || rowNum < 0 || colNum < 0)
            {
                gridImage.Visible = false;
                return;
            }
            Tile baseTile = new Tile()
            {
                ID              = (maxID + 1),
                Name            = "placeholderName",
                ProgramLocation = "",
                UseProgramIcon  = true,
                ImageLocation   = "",
                GridRowCol      = new GridLocation()
                {
                    row    = rowNum,
                    column = colNum
                }
            };
            ContextMenu cm = new ContextMenu();

            cm.MenuItems.Add("Propertes", new EventHandler(Properties_click));
            gridImage.Visible = false;
            boxLabel.Text     = String.Format("Row {0}, Column {1}", rowNum, colNum);
            var matches = rowColumns.Where(p => p.row == rowNum && p.column == colNum);

            if (addBool)
            {
                if (matches.Count() >= 1)
                {
                    GlobalVars.MessageBoxPassedVar = "AlreadyExists";
                    messageBoxForm childForm = new messageBoxForm();
                    childForm.ShowDialog();
                }
                else
                {
                    globalTileList.Add(baseTile);
                    rowColumns.Add(new GridLocation {
                        row = rowNum, column = colNum
                    });
                    MetroTile metroTile = new MetroTile();
                    metroTile.Location           = new Point(((colNum * 100) + xOffset), ((rowNum * 100) + yOffset));
                    metroTile.UseTileImage       = true;
                    metroTile.Text               = "placeholderName";
                    metroTile.ForeColor          = Color.Black;
                    metroTile.CustomForeColor    = true;
                    metroTile.TileTextFontWeight = MetroFramework.MetroTileTextWeight.Bold;
                    metroTile.TextAlign          = ContentAlignment.BottomCenter;
                    metroTile.ContextMenu        = cm;
                    metroTile.Name               = (maxID + 1).ToString();
                    maxID++;
                    metroTile.Size = new Size(71, 71);
                    this.Controls.Add(metroTile);
                    File.WriteAllText(filePath, JsonConvert.SerializeObject(globalTileList, Formatting.Indented));
                }
            }
            else if (removeBool)
            {
                if (matches.Count() >= 1)
                {
                    rowColumns.RemoveAll(p => p.row == rowNum && p.column == colNum);
                    globalTileList.RemoveAll(p => p.GridRowCol.row == rowNum && p.GridRowCol.column == colNum);
                    File.WriteAllText(filePath, JsonConvert.SerializeObject(globalTileList, Formatting.Indented));
                    foreach (var control in this.Controls.OfType <MetroTile>())
                    {
                        if (control.Location.X == ((colNum * 100) + xOffset) && control.Location.Y == ((rowNum * 100) + yOffset))
                        {
                            this.Controls.Remove(control);
                            break;
                        }
                    }
                }
            }
            addBool = removeBool = false;
        }