// Adding shortcut by button private void pnlAddShortcut_Click(object sender, EventArgs e) { lblErrorShortcut.Visible = false; // resetting error msg if (Category.ShortcutList.Count >= 20) { lblErrorShortcut.Text = "Max 20 shortcuts in one group"; lblErrorShortcut.BringToFront(); lblErrorShortcut.Visible = true; } OpenFileDialog openFileDialog = new OpenFileDialog // ask user to select exe file { InitialDirectory = @"C:\ProgramData\Microsoft\Windows\Start Menu\Programs", Title = "Create New Shortcut", CheckFileExists = true, CheckPathExists = true, Multiselect = true, DefaultExt = "exe", Filter = "Exe or Shortcut (.exe, .lnk)|*.exe;*.lnk", FilterIndex = 2, RestoreDirectory = true, ReadOnlyChecked = true, }; if (openFileDialog.ShowDialog() == DialogResult.OK) { foreach (String file in openFileDialog.FileNames) { ProgramShortcut psc = new ProgramShortcut(Environment.ExpandEnvironmentVariables(file)); //create new shortcut obj Category.ShortcutList.Add(psc); // add to panel shortcut list LoadShortcut(psc, Category.ShortcutList.Count - 1); } } }
public ucShortcut(ProgramShortcut psc, frmMain mainForm, Category category) { InitializeComponent(); Psc = psc; MotherForm = mainForm; ThisCategory = category; }
// Delete shortcut public void DeleteShortcut(ProgramShortcut psc) { Category.ShortcutList.Remove(psc); bool before = true; //int i = 0; foreach (ucProgramShortcut ucPsc in pnlShortcuts.Controls) { if (before) { ucPsc.Top -= 50; } if (ucPsc.Shortcut == psc) { //i = pnlShortcuts.Controls.IndexOf(ucPsc); pnlShortcuts.Controls.Remove(ucPsc); before = false; } } if (pnlShortcuts.Controls.Count < 5) { pnlShortcuts.Height -= 50; pnlAddShortcut.Top -= 50; } }
// Handle dropped programs into the add program/shortcut field private void pnlDragDropExt(object sender, DragEventArgs e) { var files = (String[])e.Data.GetData(DataFormats.FileDrop); // Loops through each file to make sure they exist and to add them directly to the shortcut list foreach (var file in files) { if (extensionExt.Contains(Path.GetExtension(file)) && System.IO.File.Exists(file)) { ProgramShortcut programShortcut = new ProgramShortcut(Environment.ExpandEnvironmentVariables(file)); //Create new shortcut obj Category.ShortcutList.Add(programShortcut); // Add to panel shortcut list /* * pnlShortcuts.Controls.Clear(); * LoadShortcuts(); * pnlShortcuts.ScrollControlIntoView(pnlShortcuts.Controls[0]); // scroll to the latest created control * * Note: This code was moved out of the loop to improve performance as to not keep reloading the client until the extension adding is done * As a result, the little slide animation as the icons are being added is now gone * Code may be moved back in depending on future scenario/use cases; alternative should be found for this one for better efficiency */ } } pnlShortcuts.Controls.Clear(); LoadShortcuts(); pnlShortcuts.ScrollControlIntoView(pnlShortcuts.Controls[0]); // scroll to the latest created control }
private void cmdAddShortcut_Click(object sender, EventArgs e) { lblErrorShortcut.Visible = false; // resetting error msg if (ShortcutList.Count >= 20) { lblErrorMaxShortcuts.Text = "Max 20 shortcuts in one group"; lblErrorMaxShortcuts.BringToFront(); lblErrorMaxShortcuts.Visible = true; } OpenFileDialog openFileDialog = new OpenFileDialog // ask user to select exe file { InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.StartMenu), Title = "Create New Shortcut", CheckFileExists = true, CheckPathExists = true, DefaultExt = "exe", Filter = "Program (.exe)|*.exe", FilterIndex = 2, RestoreDirectory = true, ReadOnlyChecked = true, }; if (openFileDialog.ShowDialog() == DialogResult.OK) { ProgramShortcut programShortcut = new ProgramShortcut(openFileDialog.FileName); //create new shortcut obj this.ShortcutList.Add(programShortcut); // add to panel shortcut list LoadShortcuts(); } }
private void CreateShortcut(int x, int y, ProgramShortcut programShortcut) { // creating shortcut picturebox from shortcut this.shortcutPanel = new System.Windows.Forms.PictureBox(); this.shortcutPanel.BackColor = System.Drawing.Color.Transparent; this.shortcutPanel.Location = new System.Drawing.Point(x, y); this.shortcutPanel.Size = new System.Drawing.Size(30, 30); this.shortcutPanel.BackgroundImageLayout = ImageLayout.Stretch; this.shortcutPanel.TabStop = false; this.shortcutPanel.MouseEnter += new System.EventHandler((sender, e) => Client.EnterControl(sender, e, this)); this.shortcutPanel.MouseLeave += new System.EventHandler((sender, e) => Client.LeaveControl(sender, e, this)); // Check if file is stil existing and if so render it if (File.Exists(programShortcut.FilePath)) { this.shortcutPanel.BackgroundImage = Category.loadImageCache(programShortcut.FilePath); } else // if file does not exist { this.shortcutPanel.BackgroundImage = global::client.Properties.Resources.Error; ToolTip tt = new ToolTip(); tt.InitialDelay = 0; tt.ShowAlways = true; tt.SetToolTip(this.shortcutPanel, "Program does not exist"); } this.Controls.Add(this.shortcutPanel); this.shortcutPanel.Show(); this.shortcutPanel.BringToFront(); }
private void pnlAddShortcut_Click(object sender, EventArgs e) { lblErrorShortcut.Visible = false; // resetting error msg if (Category.ShortcutList.Count >= 20) { lblErrorShortcut.Text = "Max 20 shortcuts in one group"; lblErrorShortcut.BringToFront(); lblErrorShortcut.Visible = true; } OpenFileDialog openFileDialog = new OpenFileDialog // ask user to select exe file { InitialDirectory = @"C:\ProgramData\Microsoft\Windows\Start Menu\Programs", Title = "Create New Shortcut", CheckFileExists = true, CheckPathExists = true, DefaultExt = "exe", Filter = "Exe (.exe)|*.exe", FilterIndex = 2, RestoreDirectory = true, //ShowReadOnly = true, ReadOnlyChecked = true, }; if (openFileDialog.ShowDialog() == DialogResult.OK) { ProgramShortcut programShortcut = new ProgramShortcut(openFileDialog.FileName); //create new shortcut obj Category.ShortcutList.Add(programShortcut); // add to panel shortcut list pnlShortcuts.Controls.Clear(); LoadShortcuts(); pnlShortcuts.ScrollControlIntoView(pnlShortcuts.Controls[0]); // scroll to the latest created control } }
public ucProgramShortcut(frmGroup motherForm, ProgramShortcut shortcut, int position) { InitializeComponent(); MotherForm = motherForm; Shortcut = shortcut; Position = position; }
// //------------------------------------------------------------------------------------ // // Loading category and building shortcuts private void LoadCategory() { this.Width = 0; this.Height = 45; int x = 0; int y = 0; int width = loadedCat.Width; int columns = 1; // Check if icon caches exist for the category being loaded // If not then rebuild the icon cache /* * if (!Directory.Exists(Path.Combine(Paths.ConfigPath, loadedCat.Name, "Icons"))) * { * ThisCategory.cacheIcons(); * } */ for (int i = 0; i < loadedCat.programShortcuts.Count; i++) { ProgramShortcut psc = loadedCat.programShortcuts[i]; if (columns > width) // creating new row if there are more psc than max width { x = 0; y += 45; this.Height += 45; columns = 1; } if (this.Width < ((width * 55))) { this.Width += (55); } // OLD //BuildShortcutPanel(x, y, psc); // Building shortcut controls ucShortcut pscPanel = new ucShortcut() { Psc = psc, MotherForm = this, bkgImage = loadedCat.programImages[i] }; pscPanel.Location = new System.Drawing.Point(x, y); this.Controls.Add(pscPanel); this.ControlList.Add(pscPanel); pscPanel.Show(); pscPanel.BringToFront(); // Reset values x += 55; columns++; } this.Width -= 2; // For some reason the width is 2 pixels larger than the shortcuts. Temporary fix }
// Handle adding the shortcut to list private void addShortcut(String file, bool isExtension = false) { String workingDirec = getProperDirectory(file); ProgramShortcut psc = new ProgramShortcut() { FilePath = Environment.ExpandEnvironmentVariables(file), isWindowsApp = isExtension, WorkingDirectory = workingDirec }; //Create new shortcut obj Category.ShortcutList.Add(psc); // Add to panel shortcut list LoadShortcut(psc, Category.ShortcutList.Count - 1); }
// Delete shortcut public void DeleteShortcut(ProgramShortcut psc) { resetSelection(); Category.ShortcutList.Remove(psc); resetSelection(); bool before = true; //int i = 0; foreach (ucProgramShortcut ucPsc in pnlShortcuts.Controls) { if (before) { ucPsc.Top -= 50; ucPsc.Position -= 1; } if (ucPsc.Shortcut == psc) { //i = pnlShortcuts.Controls.IndexOf(ucPsc); int controlIndex = pnlShortcuts.Controls.IndexOf(ucPsc); pnlShortcuts.Controls.Remove(ucPsc); if (controlIndex + 1 != pnlShortcuts.Controls.Count) { try { pnlShortcuts.ScrollControlIntoView(pnlShortcuts.Controls[controlIndex]); } catch { if (pnlShortcuts.Controls.Count != 0) { pnlShortcuts.ScrollControlIntoView(pnlShortcuts.Controls[controlIndex - 1]); } } } before = false; } } if (pnlShortcuts.Controls.Count < 5) { pnlShortcuts.Height -= 50; pnlAddShortcut.Top -= 50; } }
// Handle dropped programs into the add program/shortcut field private void pnlDragDropExt(object sender, DragEventArgs e) { var files = (String[])e.Data.GetData(DataFormats.FileDrop); // Loops through each file to make sure they exist and to add them directly to the shortcut list foreach (var file in files) { if (extensionExt.Contains(Path.GetExtension(file)) && System.IO.File.Exists(file) || Directory.Exists(file)) { ProgramShortcut psc = new ProgramShortcut(Environment.ExpandEnvironmentVariables(file)); //Create new shortcut obj Category.ShortcutList.Add(psc); // Add to panel shortcut list LoadShortcut(psc, Category.ShortcutList.Count - 1); } } }
private void BuildShortcutPanel(int x, int y, ProgramShortcut psc) { this.shortcutPanel = new System.Windows.Forms.PictureBox(); this.shortcutPanel.BackColor = System.Drawing.Color.Transparent; this.shortcutPanel.Location = new System.Drawing.Point(x, y); this.shortcutPanel.Size = new System.Drawing.Size(25, 25); this.shortcutPanel.BackgroundImage = System.Drawing.Icon.ExtractAssociatedIcon(psc.FilePath).ToBitmap(); this.shortcutPanel.BackgroundImageLayout = ImageLayout.Stretch; this.shortcutPanel.TabStop = false; this.shortcutPanel.Click += new System.EventHandler((sender, e) => OpenFile(sender, e, psc.FilePath)); this.shortcutPanel.Cursor = System.Windows.Forms.Cursors.Hand; this.Controls.Add(this.shortcutPanel); this.shortcutPanel.Show(); this.shortcutPanel.BringToFront(); }
// Handle adding the shortcut to list private void addShortcut(String file, bool isExtension = false) { String workingDirec = getProperDirectory(file); String appName = ""; String appFilePath = expandEnvironment(file); getShortcutName(appName, isExtension, appFilePath); ProgramShortcut psc = new ProgramShortcut() { FilePath = appFilePath, isWindowsApp = isExtension, WorkingDirectory = workingDirec, name = appName }; //Create new shortcut obj Category.ShortcutList.Add(psc); // Add to panel shortcut list LoadShortcut(psc, Category.ShortcutList.Count - 1); }
// OLD (Having some issues with the uc build, so keeping the old code below) private void BuildShortcutPanel(int x, int y, ProgramShortcut psc) { this.shortcutPic = new System.Windows.Forms.PictureBox(); this.shortcutPic.BackColor = System.Drawing.Color.Transparent; this.shortcutPic.Location = new System.Drawing.Point(25, 15); this.shortcutPic.Size = new System.Drawing.Size(25, 25); this.shortcutPic.BackgroundImage = ThisCategory.loadImageCache(psc.FilePath); // Use the local icon cache for the file specified as the icon image this.shortcutPic.BackgroundImageLayout = ImageLayout.Stretch; this.shortcutPic.TabStop = false; this.shortcutPic.Click += new System.EventHandler((sender, e) => OpenFile(sender, e, psc.FilePath)); this.shortcutPic.Cursor = System.Windows.Forms.Cursors.Hand; this.shortcutPanel.Controls.Add(this.shortcutPic); this.shortcutPic.Show(); this.shortcutPic.BringToFront(); this.shortcutPic.MouseEnter += new System.EventHandler((sender, e) => this.shortcutPanel.BackColor = Color.Black); this.shortcutPic.MouseLeave += new System.EventHandler((sender, e) => this.shortcutPanel.BackColor = System.Drawing.Color.Transparent); }
//-------------------------------------- // SHORTCUT PANEL HANLDERS //-------------------------------------- // Load up shortcut panel public void LoadShortcut(ProgramShortcut psc, int position) { pnlShortcuts.AutoScroll = false; ucProgramShortcut ucPsc = new ucProgramShortcut(this, psc, position); pnlShortcuts.Controls.Add(ucPsc); ucPsc.Show(); ucPsc.BringToFront(); if (pnlShortcuts.Controls.Count < 6) { pnlShortcuts.Height += 50; pnlAddShortcut.Top += 50; } ucPsc.Location = new Point(25, (pnlShortcuts.Controls.Count * 50) - 50); pnlShortcuts.AutoScroll = true; }
private void DeleteShortcut_Click(ProgramShortcut programShortcut) { lblErrorMaxShortcuts.Visible = false; // reset max shortcut errortext this.ShortcutList.Remove(programShortcut); // remove shortcut from list LoadShortcuts(); }