求vb高手,高分悬赏!

2024-12-19 16:39:26
推荐回答(1个)
回答1:

算我一份。
主要代码如下:

Option Explicit

Dim Changed As Boolean

Dim FN As String 'Filename

Private Sub Form_Load()
Timer1_Timer

SB.Panels(1).Text = "你的学号+姓名写在此处"
End Sub

Private Sub Form_Resize()
T.Height = Me.ScaleHeight - SB.Height
T.Width = Me.ScaleWidth
End Sub

Private Sub Form_Unload(Cancel As Integer)
If Changed Then
Dim iRet As VbMsgBoxResult
iRet = MsgBox("您的文档已经修改,是否保存?", vbQuestion + vbYesNoCancel)
If iRet = vbYes Then
If Len(FN) > 0 Then 'Has a filename
Open FN For Output As #1
Print #1, T.Text;
Close #1
Changed = False
Else
CD.DialogTitle = "保存"
CD.Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*"
CD.ShowSave
If Len(CD.FileName) > 0 Then 'Not canceled
Open CD.FileName For Output As #1
Print #1, T.Text;
Close #1
Else
Cancel = 1
End If
End If
ElseIf iRet = vbCancel Then
Cancel = 1
End If
End If
End Sub

Private Sub mnuEditCopy_Click()
Clipboard.SetText T.SelText
End Sub

Private Sub mnuEditCut_Click()
Clipboard.SetText T.SelText
T.SelText = ""
End Sub

Private Sub mnuEditFont_Click()
CD.Flags = CD.Flags Or cdlCFEffects
CD.Flags = CD.Flags Or cdlCFBoth
CD.ShowFont
T.ForeColor = CD.Color
T.FontBold = CD.FontBold
T.FontItalic = CD.FontItalic
T.FontUnderline = CD.FontUnderline
T.FontStrikethru = CD.FontStrikethru
T.FontName = CD.FontName
T.FontSize = CD.FontSize
End Sub

Private Sub mnuEditPaste_Click()
T.SelText = Clipboard.GetText
End Sub

Private Sub mnuFileExit_Click()
Unload Me
End Sub

Private Sub mnuFileNew_Click()
If Changed Then
Dim iRet As VbMsgBoxResult
iRet = MsgBox("您的文档已经修改,是否保存?", vbQuestion + vbYesNoCancel)
If iRet = vbYes Then
If Len(FN) > 0 Then 'Has a filename
Open FN For Output As #1
Print #1, T.Text;
Close #1
Changed = False
Else
CD.DialogTitle = "保存"
CD.Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*"
CD.ShowSave
If Len(CD.FileName) > 0 Then 'Not canceled
Open CD.FileName For Output As #1
Print #1, T.Text;
Close #1
Changed = False
End If
End If
ElseIf iRet = vbNo Then
FN = ""
Changed = False
End If
End If
T.Text = ""
End Sub

Private Sub mnuFileOpen_Click()
If Changed Then
Dim iRet As VbMsgBoxResult
iRet = MsgBox("您的文档已经修改,是否保存?", vbQuestion + vbYesNoCancel)
If iRet = vbYes Then
If Len(FN) > 0 Then 'Has a filename
Open FN For Output As #1
Print #1, T.Text;
Close #1
Else
CD.DialogTitle = "保存"
CD.Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*"
CD.ShowOpen
If Len(CD.FileName) > 0 Then 'Not canceled
Open CD.FileName For Output As #1
Print #1, T.Text;
Close #1
T.Text = ""
End If
End If
ElseIf iRet = vbNo Then
FN = ""
T.Text = ""
End If
End If
CD.DialogTitle = "打开"
CD.Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*"
CD.Flags = CD.Flags Or cdlOFNHideReadOnly
CD.ShowOpen
If Len(CD.FileName) > 0 Then
Dim TempStr As String
Open CD.FileName For Input As #2
Do While Not EOF(2)
Line Input #2, TempStr
T.Text = T.Text & TempStr & vbCrLf
Loop
T.Text = Left$(T.Text, Len(T.Text) - 2) 'No Cr+Lf here
Close #2
FN = CD.FileName
End If
Changed = False
End Sub

Private Sub mnuFileSave_Click()
If Len(FN) = 0 Then
mnuFileSaveAs_Click
Else
Open FN For Output As #1
Print #1, T.Text;
Close #1
End If
End Sub

Private Sub mnuFileSaveAs_Click()
CD.DialogTitle = "另存为"
CD.Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*"
CD.ShowSave
If Len(CD.FileName) > 0 Then
Open CD.FileName For Output As #1
Print #1, T.Text;
Close #1
Changed = False
FN = CD.FileName
End If
End Sub

Private Sub mnuHelpAbout_Click()
fAbout.Show vbModal
End Sub

Private Sub T_Change()
Changed = True
End Sub

Private Sub Timer1_Timer()
SB.Panels(2).Text = Time$
End Sub

Private Sub Timer2_Timer()
If Clipboard.GetFormat(vbCFText) Then
mnuEditPaste.Enabled = True
Else
mnuEditPaste.Enabled = False
End If
If T.SelLength > 0 Then
mnuEditCut.Enabled = True
mnuEditCopy.Enabled = True
Else
mnuEditCut.Enabled = False
mnuEditCopy.Enabled = False
End If
End Sub