我想在 VB.NET 中的 datagridiew 中单击时将集合代码的图像大小本地缩放到小并在图片框中显示原始大小。有可能做到吗?或者有没有最好的推荐方案?
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
fillDataGridView()
Dim repItemGraphicsEdit As New RepositoryItemPictureEdit()
repItemGraphicsEdit.SizeMode = DevExpress.XtraEditors.Controls.PictureSizeMode.Squeeze
GridControl1.RepositoryItems.Add(repItemGraphicsEdit)
GridView1.Columns("IMAGE1").ColumnEdit = repItemGraphicsEdit
GridView1.Columns("IMAGE2").ColumnEdit = repItemGraphicsEdit
End Sub
Private Sub gridView1_CustomUnboundColumnData(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs) Handles GridView1.CustomUnboundColumnData
Dim view As GridView = TryCast(sender, GridView)
Dim filename1 As String
If Not DBNull.Value.Equals(view.GetListSourceRowCellValue(e.ListSourceRowIndex, "FILENAME1")) Then
filename1 = CStr(view.GetListSourceRowCellValue(e.ListSourceRowIndex, "FILENAME1"))
Else
filename1 = String.Empty 'or Nothing depending what comes next.
End If
Dim filename2 As String
If Not DBNull.Value.Equals(view.GetListSourceRowCellValue(e.ListSourceRowIndex, "FILENAME2")) Then
filename2 = CStr(view.GetListSourceRowCellValue(e.ListSourceRowIndex, "FILENAME2"))
Else
filename2 = String.Empty 'or Nothing depending what comes next.
End If
Dim SUBFOLDERP As String
If Not DBNull.Value.Equals(view.GetListSourceRowCellValue(e.ListSourceRowIndex, "SUBFOLDERP")) Then
SUBFOLDERP = CStr(view.GetListSourceRowCellValue(e.ListSourceRowIndex, "SUBFOLDERP"))
Else
SUBFOLDERP = String.Empty 'or Nothing depending what comes next.
End If
Dim img As Image = Nothing
Try
If e.Column.Caption = "IMAGE1" Then
Dim filePath1 As String = DevExpress.Utils.FilesHelper.FindingFileName(parentpathimage & SUBFOLDERP, filename1, False)
e.Value = GetImage(filePath1)
ElseIf e.Column.Caption = "IMAGE2" Then
Dim filePath2 As String = DevExpress.Utils.FilesHelper.FindingFileName(parentpathimage & SUBFOLDERP, filename2, False)
e.Value = GetImage(filePath2)
End If
Catch
End Try
End Sub
Function GetImage(str As String) As Image
If (Images.ContainsKey(str)) Then
Return CType(Images(str), Image)
Else
Dim img = Image.FromFile(str)
Images.Add(str, img)
Return img
End If
End Function