次のコードのおかげで、画像を作成し、サムネイルとして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);
}