如何在 FlowLayoutPanel 控件中实现分页效果? [英] How can i implement the paging effect in a FlowLayoutPanel control?

查看:100
本文介绍了如何在 FlowLayoutPanel 控件中实现分页效果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

感谢以下代码,我创建了图像并将其添加到 FlowLayoutPanel 中(作为缩略图).

Thanks to the following code i create and add images - as thumbnails - to the FlowLayoutPanel.

实现非常简单.我读取目录中的可用图像并调用以下子过程.

The implementation is pretty simple. I read the available images within the directory and call the following sub procedure.

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

现在,我想扩展它.我想创建分页效果.应用程序应该读取所​​有可用的图像,但只绘制对屏幕可见的图像.

Now, i would like to extend it. I would like to create the paging effect. The application should read all the available images BUT paint only the ones that are visible to screen.

和往常一样,我不知道从哪里开始.我可以用你的灯吗?

And as usual i do not know from where to start. Could i use your lights please?

...C# 版本来了!

...and here comes the C# version!

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);
}

推荐答案

为了加快进程,一旦加载图像,您可以缓存它们,这样您就不必在每次需要它们时从文件流加载.

To speed up the process, once images are loaded you could cache them so you would not have to load from the File stream each time you required them.

>

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

While I do not know the explicit code, here is a general process:

1) 你可以有几个变量,但最重要的是 currentPage 的一个整数.

1) You could have a few variables, but the most important is an Integer for the currentPage.

2) 接下来,您需要定义每个页面上将显示多少个缩略图,一个常量或另一个整数变量.我们称之为thumbsPerPage

2) Next, you will need to define how many thumbnails will be displayed on each page, either a constant or another Integer variable. Let's call this thumbsPerPage

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

3) On the Event Handlerss (OnClick, on hover or other action events you wish), do the following:

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

4) Clear the FlowPanel of all items, probably akin to FlowPanel.Controls.Items.Clear()

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

5) Then add the following images for a given page within the range: [(currentPage-1) * thumbsPerPage, (currentPage * thumbsPerPage) - 1]

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

This assumes you are starting at 0 for your image index, and 1 for your page index

例如,每页 9 张图片:在第 1 页上您想要图像 [0,8]在第 2 页上,您需要图像 [9,17] 等.

Example, for 9 images per page: On Page 1 you want images [0,8] On Page 2 you want images [9,17], etc.

所以在代码中它会类似于

so in code it would be similar to

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

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

Lastly, convert your code to C# :)...not a requirement, but users are much more willing to help generally when it's not in VB.NET

这篇关于如何在 FlowLayoutPanel 控件中实现分页效果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆