代码
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 <&#61; 1 Then
MessageBox.Show("已经是第一页了", "五洲商慧提醒您", MessageBoxButtons.OK, MessageBoxIcon.Information)
Exit Sub
End If
Toolcurrent.Text &#61; CInt(Toolcurrent.Text) - 1
_PageNO &#61; 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 >&#61; ToollblCount.Text Then
MessageBox.Show("已经是最后一页了", "五洲商慧提醒您", MessageBoxButtons.OK, MessageBoxIcon.Information)
Exit Sub
End If
Toolcurrent.Text &#61; CInt(Toolcurrent.Text) &#43; 1
_PageNO &#61; 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 &#61; ToollblCount.Text
_PageNO &#61; 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 &#61; "" Then Exit Sub
If Not Regex.Match(TooltxtPage.Text, "^[1-9]\d*$").Success &#61; True Then
MessageBox.Show("请输入数字", "五洲商慧提醒您", MessageBoxButtons.OK, MessageBoxIcon.Information)
TooltxtPage.Text &#61; ""
Exit Sub
End If
If CInt(TooltxtPage.Text) > CInt(ToollblCount.Text) Then
MessageBox.Show("不存在此页", "五洲商慧提醒您", MessageBoxButtons.OK, MessageBoxIcon.Information)
TooltxtPage.Text &#61; ""
Exit Sub
End If
Toolcurrent.Text &#61; TooltxtPage.Text
_PageNO &#61; 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 Object, ByVal e As System.EventArgs)
CType(Events("ClickEvent"), EventHandler).Invoke(sender, e)
End RaiseEvent
End Event
End Class
Imports System.Data.OleDb
Imports System.Text.RegularExpressions
Public Class PagerWinControl
Dim strsql As String &#61; ""
&#39;总项数
Private _TotalItem As Integer
Public Property TotalItem() As Integer
Get
Return _TotalItem
End Get
Set(ByVal value As Integer)
_TotalItem &#61; value
If value &#61; 0 Then Exit Property
ToolCount.Text &#61; value
Dim result As Integer
result &#61; CInt(ToolCount.Text) Mod _PageCount
If result &#61; 0 Then
ToollblCount.Text &#61; CInt(ToolCount.Text) \ _PageCount
Else
ToollblCount.Text &#61; CInt(ToolCount.Text) \ _PageCount &#43; 1
End If
End Set
End Property
&#39;每一页的数量
Private _PageCount As Integer
Public Property PageCount() As Integer
Get
Return _PageCount
End Get
Set(ByVal value As Integer)
_PageCount &#61; value
End Set
End Property
&#39;页码
Private _PageNO As Integer
Public Property PageNO() As Integer
Get
Return _PageNO
End Get
Set(ByVal value As Integer)
_PageNO &#61; value
End Set
End Property
Private Sub TooLFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TooLFirst.Click
Toolcurrent.Text &#61; 1
_PageNO &#61; 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 <&#61; 1 Then
MessageBox.Show("已经是第一页了", "五洲商慧提醒您", MessageBoxButtons.OK, MessageBoxIcon.Information)
Exit Sub
End If
Toolcurrent.Text &#61; CInt(Toolcurrent.Text) - 1
_PageNO &#61; 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 >&#61; ToollblCount.Text Then
MessageBox.Show("已经是最后一页了", "五洲商慧提醒您", MessageBoxButtons.OK, MessageBoxIcon.Information)
Exit Sub
End If
Toolcurrent.Text &#61; CInt(Toolcurrent.Text) &#43; 1
_PageNO &#61; 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 &#61; ToollblCount.Text
_PageNO &#61; 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 &#61; "" Then Exit Sub
If Not Regex.Match(TooltxtPage.Text, "^[1-9]\d*$").Success &#61; True Then
MessageBox.Show("请输入数字", "五洲商慧提醒您", MessageBoxButtons.OK, MessageBoxIcon.Information)
TooltxtPage.Text &#61; ""
Exit Sub
End If
If CInt(TooltxtPage.Text) > CInt(ToollblCount.Text) Then
MessageBox.Show("不存在此页", "五洲商慧提醒您", MessageBoxButtons.OK, MessageBoxIcon.Information)
TooltxtPage.Text &#61; ""
Exit Sub
End If
Toolcurrent.Text &#61; TooltxtPage.Text
_PageNO &#61; 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 Object, ByVal 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&#61;Microsoft.Jet.OLEDB.4.0;Data Source&#61;|DataDirectory|\pageing.mdb;")
conn.Open()
Dim pageCount As Integer
Dim pageNO As Integer
pageNO &#61; PagerWinControl1.PageNO
pageCount &#61; PagerWinControl1.PageCount
If pageNO &#61; 1 Then
strsql &#61; "select top " & pageCount & " * from student order by id asc"
Else
strsql &#61; "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 &#61; dt
End Sub
Dim conn As New OleDbConnection("Provider&#61;Microsoft.Jet.OLEDB.4.0;Data Source&#61;|DataDirectory|\pageing.mdb;")
conn.Open()
Dim pageCount As Integer
Dim pageNO As Integer
pageNO &#61; PagerWinControl1.PageNO
pageCount &#61; PagerWinControl1.PageCount
If pageNO &#61; 1 Then
strsql &#61; "select top " & pageCount & " * from student order by id asc"
Else
strsql &#61; "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 &#61; dt
End Sub
不费话了&#xff0c;直接上代码了。自定义控件。
效果图。
希望哪个大哥给我改改。我水平太差。