vb怎样简单设计小说阅读器
发布网友
发布时间:2022-05-30 06:48
我来回答
共1个回答
热心网友
时间:2023-10-13 08:49
Private Declare Function SendMessage Lib "user32" Alias "SendMessageW" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
lParam As Any) As Long
Const EM_LINESCROLL = &HB6
Private Sub Form_Load()
'以下几个控件属性请在运行前设置好
'设置 Text1.ScrollBars = 2
'设置 Text1.MultiLine = True
'设置 Combo1.Style = 2
'设置 Combo2.Style = 2
With Combo1
.AddItem "宋体"
Combo1.AddItem "楷体"
Combo1.AddItem "黑体"
Combo1.AddItem "仿宋"
Combo1.AddItem "隶书"
Combo1.ListIndex = 0
End With
Dim i As Integer
For i = 8 To 72
Combo2.AddItem i
Next
Combo2.ListIndex = 0
File1.Pattern = "*.txt;*.htm;*.html;*.ini;*.bat;*.frm;*.vbp"
Timer1.Interval = 1000 '设置滚动速度1000等于一秒
Command1.Caption = "滚动"
End Sub
Private Sub Combo1_Click()
Text1.Font = Combo1.Text
End Sub
Private Sub Combo2_Click()
Text1.FontSize = Combo2.Text
End Sub
Private Sub Command1_Click()
Timer1.Enabled = IIf(Timer1.Enabled = False, True, False)
Command1.Caption = IIf(Command1.Caption = "滚动", "停止滚动", "滚动")
End Sub
Private Sub File1_Click()
Dim mpath As String
If Right(File1.Path, 1) <> "\" Then
mpath = File1.Path & "\"
Else
mpath = File1.Path
End If
Text1.Text = ReadFile(mpath & File1.List(File1.ListIndex))
End Sub
Private Function ReadFile(filePath As String) As String
Dim TempFile As Long
Dim LoadBytes() As Byte
On Error GoTo ErrCode
TempFile = FreeFile
Open filePath For Binary As #TempFile
ReDim LoadBytes(1 To LOF(TempFile)) As Byte
Get #TempFile, , LoadBytes
Close TempFile
ReadFile = StrConv(LoadBytes, vbUnicode)
ErrCode:
MsgBox "该文件无效!"
ReadFile = ""
End Function
Private Sub Dir1_Change()
File1.Path = Dir1.Path
End Sub
Private Sub Drive1_Change()
Dir1.Path = Me.Drive1.Drive
End Sub
Private Sub Timer1_Timer()
SendMessage Text1.hwnd, EM_LINESCROLL, 0, ByVal 1 End Sub