zoukankan      html  css  js  c++  java
  • 练习.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


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

     

    效果图。

     

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

    提示

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

  • 相关阅读:
    swiper.js 点击链接跳转后再次返回到轮播原位置
    KVO和KVC
    XML与HTML的区别
    iOS UIAppearance使用详解
    文件处理
    IOS 四种数据永久保存的方式
    UIImage图片处理(更改颜色,修改透明度,缩小,合并图片)
    从一个视图控制器切换到另一个视图控制器的几种方式
    NSString的常用方法
    NSURLRequest和NSURLConnection
  • 原文地址:https://www.cnblogs.com/Believeme/p/1673775.html
Copyright © 2011-2022 走看看