?? clstext.cls
字號:
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "clsText"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
Option Explicit
'**************************************************************
'*類模塊名稱:clsText
'*類模塊說明:一段要字符串對象
'*
'*備注:
'*
'*作者:progame
'*日期:2002-03-17 20:29:45
'***************************************************************
Private Const ModalName = "clsText"
'*字符串的類型
Public Enum typeField
tyText = 0
tyNumeric = 1
tyDateTime = 2
End Enum
'*字符串的對齊方式
Public Enum typeAlign
tyLeft = 0
tymiddle = 1
tyRight = 2
End Enum
'*打印方向
Public Enum typeOrient
Portrait = 1
Landscape = 2
End Enum
Public stringX As String '*要打印的字符串
Public fieldtype As typeField '*字符串的類型
Public showzero As Boolean '*是否顯示0
Public decimalnumber As Integer '*小數位數(-1表示不限制)
Public usesperator As Boolean '*是否使用","作為分隔符
'*備注:以上的屬性只對數字生效,其它格式在網格控件中自行完成
Public Align As typeAlign '*對齊方式
Public drawBorder As Boolean '*是否繪制邊框
Public FontName As String '*字體名
Public fontsize As Single '*字體大小
Public FontBold As Boolean '*粗體
Public FontItalic As Boolean '*斜體
Public FontUnderLine As Boolean '*下劃線
Public FontStrikeThru As Boolean '*刪除線
Public ForeColor As Long '*字體顏色
Public autowrap As Boolean '*自動換行
Public autoTrim As Boolean '*自動截斷
'*說明:如果自動換行,則此屬性不生效
'*如果是數字和日期,則此屬性也不生效
Public width As Single '*可打印的寬度
Public height As Single '*可打印的高度
Public rowheight As Single '*一行的高度
Public Left As Single '*打印的橫向起始位置
Public Top As Single '*打印的豎向起始位置
Public tag As String '*存儲額外信息
Private m_Orient As typeOrient '*打印方向(橫向、豎向)
Public Property Get orient() As typeOrient
'*得到打印方向(橫向、豎向)
orient = m_Orient
End Property
Public Property Let orient(vData As typeOrient)
'*設置打印方向(橫向、豎向)
m_Orient = vData
End Property
Public Function GetWidth() As Single
'*得到此字符串的打印寬度
GetWidth = CalWidth(GetStr, fontsize) + 2 * MYSPACE
End Function
Public Function GetHeight() As Single
'*得到此字符串的打印高度
GetHeight = CalHeight(fontsize) + 2 * MYSPACE
End Function
Public Function GetWidthVer() As Single
'*得到此字符串的打印寬度(縱向)
GetWidthVer = 2 * fontsize * 10 + 2 * MYSPACE
End Function
Public Function GetHeightVer() As Single
'*得到此字符串的打印高度(縱向)
GetHeightVer = CalHeight(fontsize) * Len(stringX)
End Function
Public Function GetRows() As Integer
'*得到此字符串的打印行數
Dim str As String
str = GetStr
'*對于數字類型,不換行
'*如果不自動換行,則只輸出一行
'*如果沒有字符串,則也只輸出一行
If fieldtype = tyNumeric _
Or (Not autowrap) _
Or Len(str) = 0 Then
GetRows = 1
Exit Function
End If
'*計算所需的行數
Dim i As Integer
Dim sWidth As Single
Dim tWidth As Single
GetRows = 0
sWidth = MYSPACE
For i = 1 To Len(str)
tWidth = CalWidth(Mid(str, i, 1), fontsize)
If sWidth + tWidth + MYSPACE > width Then
GetRows = GetRows + 1
sWidth = MYSPACE + tWidth
Else
sWidth = sWidth + tWidth
End If
Next i
GetRows = GetRows + 1
'*如果超過允許的最大行數,則只輸出MAXROWS
If GetRows > MAXROWS Then
GetRows = MAXROWS
End If
If GetRows = 0 Then
GetRows = 1
End If
End Function
Public Function GetStr() As String
'*得到格式化后的要輸出的字符串
On Error GoTo err_proc
GetStr = stringX
If fieldtype = tyNumeric Then
If usesperator Then
GetStr = Format(stringX, "###,###,###,###,##0.0#########")
End If
'*重新決定小數位數
Select Case decimalnumber
Case -1
'*不做處理
Case 0
'*無小數位
GetStr = CLng(GetStr)
Case Else
If usesperator Then
GetStr = Format(stringX, _
"###,###,###,###,##0." _
& String(decimalnumber, "0"))
Else
GetStr = Format(stringX, _
"##############0." _
& String(decimalnumber, "0"))
End If
End Select
If Not showzero Then '*如果不顯示0
If Abs(CDbl(GetStr)) < 0.000000001 Then
GetStr = ""
End If
End If
End If
'*對于文本的自動截斷處理
If fieldtype = tyText Then
If (Not autowrap) And autoTrim Then
Dim i As Integer
Dim sWidth As Single
Dim tmpStr As String
GetStr = ""
For i = 1 To Len(stringX)
sWidth = sWidth + CalWidth(Mid(stringX, i, 1), fontsize)
If sWidth > width Then
Exit For
End If
GetStr = GetStr + Mid(stringX, i, 1)
Next i
End If
End If
Exit Function
err_proc:
GetStr = ""
End Function
'**************************************************************
'*名稱:Clone
'*功能:復制對象
'*傳入參數:
'* text --目的對象
'*作者:progame
'*日期:2002-04-10 14:14:28
'***************************************************************
Public Sub Clone(text As clsText)
With text
.stringX = stringX
.fieldtype = fieldtype
.showzero = showzero
.decimalnumber = decimalnumber
.usesperator = usesperator
.Align = Align
.drawBorder = drawBorder
.FontName = FontName
.fontsize = fontsize
.FontBold = FontBold
.FontItalic = FontItalic
.FontUnderLine = FontUnderLine
.FontStrikeThru = FontStrikeThru
.ForeColor = ForeColor
.autowrap = autowrap
.autoTrim = autoTrim
.width = width
.height = height
.rowheight = rowheight
.Left = Left
.Top = Top
.orient = m_Orient
End With
End Sub
'**************************************************************
'*名稱:Save
'*功能:保存到文件
'*傳入參數:
'* filename --文件名
'*返回參數:
'* 是否保存成功
'*作者:progame
'*日期:2002-04-16 20:47:42
'***************************************************************
Public Function Save(FileName As String, section As String) As Boolean
Save = SetIni(FileName, section, "stringx", CStr(stringX))
Save = Save And SetIni(FileName, section, "fieldtype", CStr(fieldtype))
Save = Save And SetIni(FileName, section, "showzero", CStr(showzero))
Save = Save And SetIni(FileName, section, "decimalnumber", CStr(decimalnumber))
Save = Save And SetIni(FileName, section, "usesperator", CStr(usesperator))
Save = Save And SetIni(FileName, section, "align", CStr(Align))
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -