繁体   English   中英

如何在FlowLayoutPanel控件中实现分页效果?

[英]How can i implement the paging effect in a FlowLayoutPanel control?

由于以下代码,我创建了图像并将其作为缩略图添加到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);
}

为了加快处理速度,一旦加载了图像,您就可以对其进行缓存,这样就不必在每次需要它们时都从File流中进行加载。

虽然我不知道显式代码,但这是一个常规过程:

1)您可以有一些变量,但是最重要的是currentPage的Integer。

2)接下来,您将需要定义在每个页面上显示多少个缩略图(常量或另一个Integer变量)。 我们称这个thumbsPerPage

3)在事件处理程序(OnClick,悬停或您希望的其他动作事件)上,执行以下操作:

4)清除所有项目的FlowPanel,可能类似于FlowPanel.Controls.Items.Clear()

5)然后为范围内的给定页面添加以下图像:[(currentPage-1)* thumbsPerPage,(currentPage * thumbsPerPage)-1]

假设您的图片索引从0开始,页面索引从1开始

例如,每页9张图像:在第1页上,您需要图像[0,8]在第2页上,您需要图像[9,17],依此类推。

所以在代码中它将类似于

FlowPanel.Items.Clear()
for(int i = (currentPage-1) * thumbsPerPage; i < (currentPage * thumbsPerPage) - 1; i++)
   FlowPanel.Controls.Add(Pedits[i])

最后,将您的代码转换为C#:)...不是必需的,但是当不在VB.NET中时,用户通常更愿意提供帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM