private void LoadImages() { try { if (_files == null) { return; } if (this.WindowState == FormWindowState.Minimized) { return; } dataViewImages.Rows.Clear(); dataViewImages.Columns.Clear(); int numColumnsForWidth = (dataViewImages.Width - 5) / (_imageSize + 20); int numRows = 0; int numImagesRequired = 0; if (_currentEndImageIndex > _files.Count) { // Are we requesting to display more images than we actually have? If so then reduce if (_currentStartImageIndex == 0) { numImagesRequired = _files.Count; } else { numImagesRequired = (_currentEndImageIndex - _currentStartImageIndex) - (_currentEndImageIndex - _files.Count); } } else { // Calculated the number of rows we will need for normal use numImagesRequired = _currentEndImageIndex - _currentStartImageIndex; } numRows = numImagesRequired / numColumnsForWidth; // Do we have a an overfill for a row if (numImagesRequired % numColumnsForWidth > 0) { numRows += 1; } // Catch when we have less images than the maximum number of columns for the DataGridView width if (numImagesRequired < numColumnsForWidth) { numColumnsForWidth = numImagesRequired; } int numGeneratedCells = numRows*numColumnsForWidth; // Dynamically create the columns for (int index = 0; index < numColumnsForWidth; index++) { DataGridViewImageColumn dataGridViewColumn = new DataGridViewImageColumn(); dataViewImages.Columns.Add(dataGridViewColumn); dataViewImages.Columns[index].Width = _imageSize + 20; } // Create the rows for (int index = 0; index < numRows; index++) { dataViewImages.Rows.Add(); dataViewImages.Rows[index].Height = _imageSize + 20; } int columnIndex = 0; int rowIndex = 0; for (int index = _currentStartImageIndex; index < _currentStartImageIndex + numImagesRequired; index++) { // Load the image from the file and add to the DataGridView Image image = Helper.ResizeImage(_files[index], _imageSize, _imageSize, false); dataViewImages.Rows[rowIndex].Cells[columnIndex].Value = image; dataViewImages.Rows[rowIndex].Cells[columnIndex].ToolTipText = Path.GetFileName(_files[index]); // Have we reached the end column? if so then start on the next row if (columnIndex == numColumnsForWidth - 1) { rowIndex++; columnIndex = 0; } else { columnIndex++; } } // Blank the unused cells if (numGeneratedCells > numImagesRequired) { for (int index = 0; index < numGeneratedCells - numImagesRequired; index++) { DataGridViewCellStyle dataGridViewCellStyle = new DataGridViewCellStyle(); dataGridViewCellStyle.NullValue = null; dataGridViewCellStyle.Tag = "BLANK"; dataViewImages.Rows[rowIndex].Cells[columnIndex + index].Style = dataGridViewCellStyle; } } if (_currentStartImageIndex == 0) { btnPreviousImages.Enabled = false; } else { btnPreviousImages.Enabled = true; } if (_currentEndImageIndex < _files.Count) { btnNextImages.Enabled = true; } else { btnNextImages.Enabled = false; } } catch (Exception ex) { Console.WriteLine(ex); } }
private void dataViewImages_CellContentClick(object sender, DataGridViewCellEventArgs e) { Image image =(Image)dataViewImages.SelectedCells; pictureBox.Image = image; tsbSave.Enabled = true; tsbRotate.Enabled = true; tsbCCRotate.Enabled = true }
Image image =(Image)dataViewImages.SelectedCells
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)