編寫一個報表處理軟件,想攜程“綠色”得:
1.免安裝,軟件復制即可使用。
2.不使用表格控件,尤其是第三方控件,以避免麻煩和想不到得毛病。
那么就需要編程畫表格,并提供翻頁功能,因為屏幕空間有限,只能顯示10行,蕞多11行。
效果如上面支持所示。
設計過程:
一,打開軟件開發工具,這里以VB為例,新增窗體一個。
二,編寫代碼畫表格。
這里用label畫表格,好處時即能輸出文字 還能通過背景色和間距產生表格效果 ,經濟實惠。
代碼如下:
先聲明幾個變量
Dim startNum As Byte, i As Integer, pgNum As Byte
Const endNum As Byte = 55, ANum As Byte = 11
Const X0 As Integer = 2200, Y0 As Integer = 1400
Const Wv As Integer = 1000, Wv2 As Integer = 5980
Const Hv As Integer = 405, Hv2 As Integer = 385
然后寫一個產生label控件數組得模塊,設定間距,形成表格。
Private Sub myLabload(nCount As Byte)
' 功能:加載控件,畫表格
Dim n As Byte
i = 0
For n = 1 To nCount
Load Lab(n) '產生控件數組
With Lab(n)
.Left = X0
.Top = Y0 + i * Hv
.Width = Wv
.Height = Hv2
.BackColor = vbWhite
.BackStyle = 1
.ZOrder 0
If n <= ANum Then .Visible = True
End With
Load LabC(n)
With LabC(n)
.Left = X0 + Wv + 30
.Top = Y0 + i * Hv
.Width = Wv2
.Height = Hv2
.Alignment = 0
.BackColor = vbWhite
.BackStyle = 1
.ForeColor = &H800000
.ZOrder 0
If n <= ANum Then .Visible = True
End With
i = i + 1
Next
LabBj.Move 2160, 960, Wv + Wv2 + 100, Hv * 12 + 60
LabBj.ZOrder 1
End Sub
接下來編寫翻頁模塊(向后)
Private Sub pgUpShow()
' 功能:向后翻頁
Dim n As Integer
If pgNum = 5 Then Exit Sub
i = 0
For n = startNum To startNum + ANum - 1
Lab(n).Visible = False
LabC(n).Visible = False
If n + ANum <= endNum Then
Lab(n + ANum).Move X0, Y0 + i * Hv, Wv, Hv2
Lab(n + ANum).Visible = True
Lab(n + ANum).ZOrder 0
LabC(n + ANum).Move X0 + Wv + 30, Y0 + i * Hv, Wv2, Hv2
LabC(n + ANum).Visible = True
LabC(n + ANum).ZOrder 0
End If
i = i + 1
Next
startNum = startNum + ANum
pgNum = pgNum + 1
'Lab(0).Caption = pgNum
End Sub
再編寫向前翻頁模塊
Private Sub pgDownShow()
' 功能:向前翻頁
Dim n As Integer
If pgNum = 1 Then Exit Sub
i = 10
For n = startNum + ANum - 1 To startNum Step -1
If n < endNum Then
Lab(n).Visible = False
LabC(n).Visible = False
End If
Lab(n - ANum).Move X0, Y0 + i * Hv, Wv, Hv2
Lab(n - ANum).Visible = True
Lab(n - ANum).ZOrder 0
LabC(n - ANum).Move X0 + Wv + 30, Y0 + i * Hv, Wv2, Hv2
LabC(n - ANum).Visible = True
LabC(n - ANum).ZOrder 0
i = i - 1
Next
startNum = startNum - ANum
pgNum = pgNum - 1
End Sub
窗體啟動時,在load事件里調用第壹個模塊, 即畫表格模塊。
Private Sub Form_Load()
' 窗體啟動
Call myLabload(endNum)
startNum = 1
pgNum = 1
End Sub
翻頁效果如下支持: