Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在FlowLayoutPanel控件中实现分页效果?_C#_Vb.net_Winforms_Paging_Flowlayoutpanel - Fatal编程技术网

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

C# 如何在FlowLayoutPanel控件中实现分页效果?,c#,vb.net,winforms,paging,flowlayoutpanel,C#,Vb.net,Winforms,Paging,Flowlayoutpanel,由于下面的代码,我创建了图像并将其添加到FlowLayoutPanel中(作为缩略图) 实现非常简单。我读取目录中的可用图像并调用以下子过程 Private Sub LoadImages(ByVal FlowPanel As FlowLayoutPanel, ByVal fi As FileInfo) Pedit = New DevExpress.XtraEditors.PictureEdit Pedit.Width = txtIconsWidth.EditVal

由于下面的代码,我创建了图像并将其添加到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版本来了


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

虽然我不知道明确的代码,但这里有一个一般过程:

1) 您可以有几个变量,但最重要的是当前页面的整数

2) 接下来,您需要定义每页上显示的缩略图数量,可以是常量,也可以是另一个整数变量。让我们称之为拇指页面

3) 在事件句柄(OnClick、On hover或其他您希望的操作事件)上,执行以下操作:

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

5) 然后为范围内的给定页面添加以下图像: [(当前页面-1)*拇指页面,(当前页面*拇指页面)-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])
FlowPanel.Items.Clear()
对于(int i=(当前页面-1)*拇指页面;i<(当前页面*拇指页面)-1;i++)
FlowPanel.Controls.Add(Pedits[i])
最后,将代码转换为C#:)……这不是一项要求,但当它不在VB.NET中时,用户通常更愿意提供帮助

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