Exemplo n.º 1
0
        /// <summary>
        /// Manipulates Settings button.
        /// </summary>
        private void InitializeSettingsButton()
        {
            Models.ShortcutModel SettingsShortcut = new Models.ShortcutModel();
            Button button = new Button();
            Image  image  = new Image();

            SettingsShortcut.ID           = ShortcutList.Count;
            SettingsShortcut.BitmapSource = new BitmapImage(new Uri("/Icons/Settings.ico", UriKind.Relative));

            image.Source = SettingsShortcut.BitmapSource;

            SettingsShortcut.Name = "Settings";

            SettingsButton.MouseEnter += (s, f) => { TestTextBlock.Text = SettingsShortcut.Name; };

            button.Content = image;                                                              //  Add image to the button
            button.Click  += (s, f) => { Settings Settings = new Settings(); Settings.Show(); }; // Button click event
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates Exit button.
        /// </summary>
        private void InitializeExitButton()
        {
            Models.ShortcutModel ExitShortcut = new Models.ShortcutModel();
            Button button = new Button();
            Image  image  = new Image();

            ExitShortcut.ID           = ShortcutList.Count;
            ExitShortcut.BitmapSource = new BitmapImage(new Uri("/Icons/Exit.ico", UriKind.Relative));

            TestTextBlock.Visibility = Visibility.Hidden;

            ExitShortcut.Name = "Exit";

            ExitButton.MouseEnter += (s, f) => { TestTextBlock.Text = ExitShortcut.Name; };

            image.Source = ExitShortcut.BitmapSource;

            ExitButton.Content = image; //  Add image to the button
            ExitButton.Click  += (s, f) => {
                //foreach (Button item in MainGrid.Children)
                //{
                //    if (item == MainGrid.Children[0] || item == MainGrid.Children[1])
                //    {

                //    }
                //    else
                //    {
                //        collection.Add(item.)
                //    }
                //    //  Store shortcut in global List for later re-use.
                //    Resources.Add(val, item);
                //    //collection.Add(item.ToString());
                //    val++;
                //}
                //Properties.Settings.Default.ShortcutList = collection;
                //Properties.Settings.Default.Save();
                Properties.Settings.Default.ShortcutList = collection;
                Properties.Settings.Default.Save();
                Environment.Exit(0);
            };   // Button click event
        }
Exemplo n.º 3
0
        private void new_icon(string path)
        {
            Models.ShortcutModel shortcut = new Models.ShortcutModel();
            Button button = new Button();
            Image  image  = new Image();

            shortcut.ID = ShortcutList.Count;

            shortcut.Path = path;

            shortcut.Name = System.IO.Path.GetFileNameWithoutExtension(shortcut.Path);

            try
            {
                shortcut.BitmapSource = Imaging.CreateBitmapSourceFromHIcon(
                    ShellEx.GetBitmapFromFilePath(shortcut.Path, ShellEx.IconSizeEnum.ExtraLargeIcon).GetHicon(),
                    Int32Rect.Empty,
                    BitmapSizeOptions.FromEmptyOptions());

                image.Source   = shortcut.BitmapSource;
                button.Content = shortcut.FileButton;
            }

            catch (FileNotFoundException)
            {
                image.Source = new BitmapImage(new Uri("/Icons/FolderIcon.ico", UriKind.Relative));
            }

            MainGrid.Columns += 1;
            MainGrid.Children.Add(button);                                // Add button at the end of Items Control in Main Window
            button.Content = image;                                       //  Add image to the button
            button.Click  += (s, f) => { Process.Start(shortcut.Path); }; // Button click event
            collection.Add(shortcut.Path);
            ContextMenu contextMenu = new ContextMenu();

            button.ContextMenu = contextMenu;
            button.ToolTip     = shortcut.Name;
            // Re used Ryan's deletion code for this purpouse + Remove button from Item Control + resize window
            MenuItem DeleteItem = new MenuItem();

            DeleteItem.Header = "Delete";
            button.ContextMenu.Items.Clear();
            DeleteItem.Click += (s, f) => {
                collection.Remove(shortcut.Path);
                MainGrid.Children.Remove(button);
                MainGrid.Columns -= 1;
                MainGrid.Width    = MainGrid.Children.Count * Properties.Settings.Default.IconSize;
                this.Width        = this.MainGrid.Children.Count * Properties.Settings.Default.IconSize + 50;
                halfWidth         = this.Width / 2;
                this.Left         = SystemParameters.PrimaryScreenWidth / 2 - halfWidth;
            };
            button.MouseEnter += (s, f) => { TestTextBlock.Text = shortcut.Name; };

            button.ContextMenu.Items.Add(DeleteItem);


            // Update Sizing and Positioning
            MainGrid.Width = MainGrid.Children.Count * Properties.Settings.Default.IconSize;
            this.Width     = this.MainGrid.Children.Count * Properties.Settings.Default.IconSize + 50;
            halfWidth      = this.Width / 2;
            this.Left      = SystemParameters.PrimaryScreenWidth / 2 - halfWidth;
        }