• 练习.net WinForm开发(一):自定义分页控件(2)


    代码
    Imports System.Data
    Imports System.Data.OleDb
    Imports System.Text.RegularExpressions
    Public Class PagerWinControl
        
    Dim strsql As String = ""
        
    '总项数
        Private _TotalItem As Integer
        
    Public Property TotalItem() As Integer
            
    Get
                
    Return _TotalItem
            
    End Get
            
    Set(ByVal value As Integer)
                _TotalItem 
    = value
                
    If value = 0 Then Exit Property
                ToolCount.Text 
    = value
                
    Dim result As Integer
                result 
    = CInt(ToolCount.Text) Mod _PageCount
                
    If result = 0 Then
                    ToollblCount.Text 
    = CInt(ToolCount.Text) \ _PageCount
                
    Else
                    ToollblCount.Text 
    = CInt(ToolCount.Text) \ _PageCount + 1
                
    End If
            
    End Set
        
    End Property
        
    '每一页的数量
        Private _PageCount As Integer
        
    Public Property PageCount() As Integer
            
    Get
                
    Return _PageCount
            
    End Get
            
    Set(ByVal value As Integer)
                _PageCount 
    = value
            
    End Set
        
    End Property
        
    '页码
        Private _PageNO As Integer
        
    Public Property PageNO() As Integer
            
    Get
                
    Return _PageNO
            
    End Get
            
    Set(ByVal value As Integer)
                _PageNO 
    = value
            
    End Set
        
    End Property
        
    Private Sub TooLFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TooLFirst.Click
            Toolcurrent.Text 
    = 1
            _PageNO 
    = 1
            
    RaiseEvent OnButtonClick(sender, e)
        
    End Sub

        
    Private Sub ToolPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolPrevious.Click
            
    If Toolcurrent.Text <= 1 Then
                MessageBox.Show(
    "已经是第一页了""五洲商慧提醒您", MessageBoxButtons.OK, MessageBoxIcon.Information)
                
    Exit Sub
            
    End If
            Toolcurrent.Text 
    = CInt(Toolcurrent.Text) - 1
            _PageNO 
    = CInt(Toolcurrent.Text)
            
    RaiseEvent OnButtonClick(sender, e)
        
    End Sub

        
    Private Sub ToolNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolNext.Click
            
    If Toolcurrent.Text >= ToollblCount.Text Then
                MessageBox.Show(
    "已经是最后一页了""五洲商慧提醒您", MessageBoxButtons.OK, MessageBoxIcon.Information)
                
    Exit Sub
            
    End If
            Toolcurrent.Text 
    = CInt(Toolcurrent.Text) + 1
            _PageNO 
    = CInt(Toolcurrent.Text)
            
    RaiseEvent OnButtonClick(sender, e)
        
    End Sub

        
    Private Sub ToolLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolLast.Click
            Toolcurrent.Text 
    = ToollblCount.Text
            _PageNO 
    = CInt(ToollblCount.Text)
            
    RaiseEvent OnButtonClick(sender, e)
        
    End Sub

        
    Private Sub ToolGO_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolGO.Click
            
    If TooltxtPage.Text = "" Then Exit Sub
            
    If Not Regex.Match(TooltxtPage.Text, "^[1-9]\d*$").Success = True Then
                MessageBox.Show(
    "请输入数字""五洲商慧提醒您", MessageBoxButtons.OK, MessageBoxIcon.Information)
                TooltxtPage.Text 
    = ""
                
    Exit Sub
            
    End If
            
    If CInt(TooltxtPage.Text) > CInt(ToollblCount.Text) Then
                MessageBox.Show(
    "不存在此页""五洲商慧提醒您", MessageBoxButtons.OK, MessageBoxIcon.Information)
                TooltxtPage.Text 
    = ""
                
    Exit Sub
            
    End If
            Toolcurrent.Text 
    = TooltxtPage.Text
            _PageNO 
    = CInt(Toolcurrent.Text)
            
    RaiseEvent OnButtonClick(sender, e)
        
    End Sub
        
    Public Custom Event OnButtonClick As EventHandler
            
    AddHandler(ByVal value As EventHandler)
                Events.AddHandler(
    "ClickEvent", value)
            
    End AddHandler

            
    RemoveHandler(ByVal value As EventHandler)
                Events.RemoveHandler(
    "ClickEvent", value)
            
    End RemoveHandler

            
    RaiseEvent(ByVal sender As ObjectByVal e As System.EventArgs)
                
    CType(Events("ClickEvent"), EventHandler).Invoke(sender, e)
            
    End RaiseEvent
        
    End Event
    End Class

    调用代码

    代码
    Private Sub PagerWinControl1_OnButtonClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PagerWinControl1.OnButtonClick
            
    Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\pageing.mdb;")
            conn.Open()
            
    Dim pageCount As Integer
            
    Dim pageNO As Integer
            pageNO 
    = PagerWinControl1.PageNO
            pageCount 
    = PagerWinControl1.PageCount
            
    If pageNO = 1 Then
                strsql 
    = "select top " & pageCount & " * from student order by id asc"
            
    Else
                strsql 
    = "select top " & pageCount & " * from student where id not in(select top " & pageCount * pageNO - pageCount & " id from student) order by id asc"
            
    End If
            
    Dim ad As New OleDbDataAdapter(strsql, conn)
            
    Dim dt As New DataTable
            ad.Fill(dt)
            DataGridView1.DataSource 
    = dt
        
    End Sub


    不费话了,直接上代码了。自定义控件。

     

    效果图。

     

    希望哪个大哥给我改改。我水平太差。

    提示

           如果您觉得本篇文章对您有用请评论。

  • 相关阅读:
    bootstrap4 Reboot details summary 美化(点选禁止选中文本,单行隐藏角标,多行后移)
    在C#中,Newtonsoft.Json + dynamic动态解析jsonString,jsonString转实体
    在C#中,Windows Console控制台 设置控制台标题、禁用关闭按钮、关闭快速编辑模式、插入模式
    MySql数据库中,判断表、表字段是否存在,不存在就新增
    Windows 10安装Docker 步骤及顺序
    AES加密解密 助手类 CBC加密模式
    处理模板页菜单高亮
    C# 按不同的字节编码,通过字节数去截取字符串
    2018年4月13日,祝自己24岁生日快乐!
    一个数值保存复选框的值
  • 原文地址:https://www.cnblogs.com/Believeme/p/1673775.html
Copyright © 2020-2023  润新知