/// <summary> /// populates the filesGrid List with the current displayed files as a list. /// </summary> private void switchToGrid() { menuShape = MenuView.GRID; filesGrid.Clear(); foreach (var file in filesList) { FileGridView file_grid = new FileGridView(file.GetName); filesGrid.Add(file_grid); } fileHost_panel.Controls.Clear(); foreach (var file in filesGrid) { fileHost_panel.Controls.Add(file); } int curr_x = 3, curr_y = 0; fileCount = 0; FileGridView dummy = new FileGridView(); while (fileCount < filesGrid.Count && curr_x < fileHost_panel.Width && curr_y < fileHost_panel.Height) { while (curr_x < fileHost_panel.Width - dummy.Width && fileCount < filesGrid.Count) { lastGridFilePosition = new Point(curr_x, curr_y); filesGrid[fileCount].Location = lastGridFilePosition; fileHost_panel.Controls.Add(filesGrid[fileCount]); fileCount++; curr_x += dummy.Width + gridFiles_X_spacing; } curr_x = x_pivot; curr_y += gridFiles_Y_spacing + dummy.Height; } }
/// <summary> /// /// </summary> /// <returns></returns> private Point getGridFilePosition() { FileGridView dummy = new FileGridView(); int items = filesGrid.Count; if (lastGridFilePosition.X < fileHost_panel.Width - 2 * dummy.Width - gridFiles_X_spacing) { lastGridFilePosition.X += dummy.Width + gridFiles_X_spacing; } else { lastGridFilePosition.X = x_pivot; lastGridFilePosition.Y += gridFiles_Y_spacing + dummy.Height; } return(lastGridFilePosition); }
public void addFile() { if (menuShape == MenuView.LIST) { FileListEntry newFile = new FileListEntry("E:/path/to/file" + fileCount.ToString()) { Dock = DockStyle.Top, Tag = fileCount }; filesList.Add(newFile); newFile.AlternateBackColor(fileCount); fileHost_panel.Controls.Add(newFile); } else if (menuShape == MenuView.GRID) { FileGridView newFile = new FileGridView("E:/path/to/file" + fileCount.ToString()) { Location = getGridFilePosition() }; filesGrid.Add(newFile); fileHost_panel.Controls.Add(newFile); } fileCount++; }