Ejemplo n.º 1
0
        /// <summary>
        /// Displays an <see cref="OpenFileDialog"/> with Multiselect enabled and creates a <see cref="UserControlFile"/> instance
        /// for each file provided in the dialog.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonAddFiles_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Multiselect = true;

            if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                foreach (string file in openFileDialog.FileNames)
                {
                    UserControlFile userControlFile = new UserControlFile(file, this);

                    // Determine the y coordinate of the new user control
                    int numberOfFiles = UserControlFiles.Count;
                    int yCoordinate   = (userControlFile.Height + 10) * numberOfFiles;
                    userControlFile.Location = new Point(0, yCoordinate);

                    UserControlFiles.Add(userControlFile);
                    panelFiles.Controls.Add(userControlFile);
                }
            }

            // If there's at least one file, enable certain buttons
            if (UserControlFiles.Count > 0)
            {
                buttonRemoveAll.Enabled      = true;
                buttonRemoveSelected.Enabled = true;
            }

            RebuildPanelControls();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Prompts a folder browser dialog, gets all the file paths from the selected folder, and adds them to the file list.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonOpenFolder_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();

            if (folderBrowserDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                foreach (string file in System.IO.Directory.GetFiles(folderBrowserDialog.SelectedPath))
                {
                    UserControlFile userControlFile = new UserControlFile(file, this);

                    // Determine the y coordinate of the new user control
                    int numberOfFiles = UserControlFiles.Count;
                    int yCoordinate   = (userControlFile.Height + 10) * numberOfFiles;
                    userControlFile.Location = new Point(0, yCoordinate);

                    UserControlFiles.Add(userControlFile);
                    panelFiles.Controls.Add(userControlFile);
                }

                // If there's at least one file, enable certain buttons
                if (UserControlFiles.Count > 0)
                {
                    buttonRemoveAll.Enabled      = true;
                    buttonRemoveSelected.Enabled = true;
                }

                RebuildPanelControls();
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Tries to set userControlFile's position at newPosition.
        /// If there is an element at that index, will perform a swap between these 2 elements.
        /// If newPosition is higher than <see cref="UserControlFiles"/>'s Count, resets userControlFile's numeric value to
        /// its original value.
        /// </summary>
        /// <param name="userControlFile"></param>
        /// <param name="newPosition"></param>
        public void ChangePosition(UserControlFile userControlFile, int newPosition)
        {
            int oldPosition = UserControlFiles.IndexOf(userControlFile);

            if (oldPosition == newPosition)
            {
                return;
            }

            if (newPosition >= UserControlFiles.Count)
            {
                userControlFile.FileNumber = oldPosition;
                return;
            }

            UserControlFile userControlFileToBeSwappedWith = UserControlFiles[newPosition];

            UserControlFiles[newPosition] = userControlFile;
            UserControlFiles[oldPosition] = userControlFileToBeSwappedWith;

            RebuildPanelControls();

            //MessageBox.Show("File " + userControlFile.FileName + " wants to change from position " + oldPosition + " to " + newPosition);
        }