感谢以下代码,我创建并添加图像(作为缩略图)到 FlowLayoutPanel。
实现非常简单。我读取目录中的可用图像并调用以下子过程。
Private Sub LoadImages(ByVal FlowPanel As FlowLayoutPanel, ByVal fi As FileInfo)
Pedit = New DevExpress.XtraEditors.PictureEdit
Pedit.Width = txtIconsWidth.EditValue
Pedit.Height = Pedit.Width / (4 / 3)
Dim fs As System.IO.FileStream
fs = New System.IO.FileStream(fi.FullName, IO.FileMode.Open, IO.FileAccess.Read)
Pedit.Image = System.Drawing.Image.FromStream(fs)
fs.Close()
fs.Dispose()
Pedit.Properties.SizeMode = DevExpress.XtraEditors.Controls.PictureSizeMode.Zoom
If FlowPanel Is flowR Then
AddHandler Pedit.MouseClick, AddressOf Pedit_MouseClick
AddHandler Pedit.MouseEnter, AddressOf Pedit_MouseEnter
AddHandler Pedit.MouseLeave, AddressOf Pedit_MouseLeave
End If
FlowPanel.Controls.Add(Pedit)
End Sub
现在,我想扩展它。我想创建分页效果。应用程序应该读取所有可用的图像,但只绘制屏幕可见的图像。
和往常一样,我不知道从哪里开始。请问我可以用你的灯吗?
...C# 版本来了!
private void LoadImages(FlowLayoutPanel FlowPanel, FileInfo fi)
{
Pedit = new DevExpress.XtraEditors.PictureEdit();
Pedit.Width = txtIconsWidth.EditValue;
Pedit.Height = Pedit.Width / (4 / 3);
System.IO.FileStream fs = null;
fs = new System.IO.FileStream(fi.FullName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
Pedit.Image = System.Drawing.Image.FromStream(fs);
fs.Close();
fs.Dispose();
Pedit.Properties.SizeMode = DevExpress.XtraEditors.Controls.PictureSizeMode.Zoom;
if (object.ReferenceEquals(FlowPanel, flowR)) {
Pedit.MouseClick += Pedit_MouseClick;
Pedit.MouseEnter += Pedit_MouseEnter;
Pedit.MouseLeave += Pedit_MouseLeave;
}
FlowPanel.Controls.Add(Pedit);
}