private void clickItem(object sender, EventArgs e) { int id = FuncParser.stringToInt(((Control)sender).Tag.ToString()); if (Control.ModifierKeys == Keys.None) { int index = appID.IndexOf(id); if (index != -1) { processStart(appLaunchPath[index], appLaunchArgs[index]); } } else { DialogResult dialog = MessageBox.Show("Удалить выбранный ярлык?", "Удаление элемента", MessageBoxButtons.YesNo); if (dialog == DialogResult.Yes) { List <string> tempList = new List <string>(); for (int i = 1; i <= totalFiles; i++) { if (i != id) { tempList.Add(FuncParser.stringRead(appINI, "Files", "ShortcutFile_" + i.ToString())); } FuncParser.deleteKey(appINI, "Files", "ShortcutFile_" + i.ToString()); } for (int i = 0; i < tempList.Count; i++) { FuncParser.iniWrite(appINI, "Files", "ShortcutFile_" + (i + 1).ToString(), tempList[i]); } totalFiles = tempList.Count; FuncParser.iniWrite(appINI, "General", "TotalFiles", totalFiles.ToString()); tempList.Clear(); Application.Restart(); } } }
private void createShortcut(int number, string line) { itemsOnLine++; if (nextLine) { ClientSize = new System.Drawing.Size(ClientSize.Width, ClientSize.Height + offSetY); nextLine = false; } appID.Add(number); string[] parseLine = line.Split(new string[] { "|" }, StringSplitOptions.None); if (parseLine[0][1].ToString() == "A") { appLaunchPath.Add(parseLine[2]); } else if (parseLine[0][1].ToString() == "R") { appLaunchPath.Add(trimAppPath(FuncParser.stringToInt(parseLine[0][2].ToString())) + parseLine[2]); } if (parseLine.Length == 4 && !String.IsNullOrEmpty(parseLine[3])) { appLaunchArgs.Add(parseLine[3]); } else { appLaunchArgs.Add(""); } PictureBox newPictureBox = new PictureBox(); newPictureBox.BackColor = System.Drawing.Color.Transparent; newPictureBox.Location = new System.Drawing.Point(iconPosX, iconPosY); newPictureBox.Name = "NewPictureBox_" + number.ToString(); newPictureBox.Size = new System.Drawing.Size(32, 32); newPictureBox.Cursor = System.Windows.Forms.Cursors.Hand; newPictureBox.Tag = number; newPictureBox.DoubleClick += clickItem; if (parseLine[0][0].ToString() == "F") { Image image = iconFromFile(appLaunchPath[appLaunchPath.Count - 1]); if (image.Width > 32 || image.Height > 32) { image = resizeIcon(image, 32, 32); } newPictureBox.Image = image; } else if (parseLine[0][0].ToString() == "D") { newPictureBox.Image = Properties.Resources.folder; } Controls.Add(newPictureBox); newPictureBox.BringToFront(); Label newLabel = new Label(); newLabel.BackColor = System.Drawing.Color.Transparent; newLabel.Font = new System.Drawing.Font("Arial", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); newLabel.Location = new System.Drawing.Point(labelPosX, labelPosY); newLabel.Name = "NewLabel_" + number.ToString(); newLabel.Size = new System.Drawing.Size(78, 30); newLabel.TextAlign = System.Drawing.ContentAlignment.TopCenter; newLabel.Text = parseLine[1]; newLabel.Cursor = System.Windows.Forms.Cursors.Hand; newLabel.Tag = number; newLabel.DoubleClick += clickItem; Controls.Add(newLabel); newLabel.BringToFront(); if (itemsOnLine < maxItemsOnLine) { iconPosX += offSetX; labelPosX += offSetX; } else { iconPosX = 35; labelPosX = 12; iconPosY += offSetY; labelPosY += offSetY; itemsOnLine = 0; nextLine = true; } }