⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.frm

📁 用VB编程实现word的基本功能
💻 FRM
字号:
VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "comdlg32.ocx"
Object = "{3B7C8863-D78F-101B-B9B5-04021C009402}#1.2#0"; "RICHTX32.OCX"
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "msflxgrd.ocx"
Begin VB.Form table 
   Caption         =   "Form1"
   ClientHeight    =   3195
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4680
   LinkTopic       =   "Form1"
   MDIChild        =   -1  'True
   ScaleHeight     =   3195
   ScaleWidth      =   4680
   Begin RichTextLib.RichTextBox text1 
      Height          =   495
      Left            =   3120
      TabIndex        =   1
      Top             =   1320
      Width           =   735
      _ExtentX        =   1296
      _ExtentY        =   873
      _Version        =   393217
      TextRTF         =   $"Form1.frx":0000
   End
   Begin MSComDlg.CommonDialog CommonDialog1 
      Left            =   2040
      Top             =   1920
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   393216
   End
   Begin MSFlexGridLib.MSFlexGrid MSFlexGrid1 
      Height          =   1095
      Left            =   960
      TabIndex        =   0
      Top             =   600
      Width           =   1335
      _ExtentX        =   2355
      _ExtentY        =   1931
      _Version        =   393216
      Rows            =   102
      Cols            =   27
   End
End
Attribute VB_Name = "table"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Form_Load()
    text1.Move -10000, -10000, 1, 1
     MSFlexGrid1.TextMatrix(0, 0) = "xh"
      For i = 1 To 26
       MSFlexGrid1.TextMatrix(0, i) = Chr(64 + i)
       Next i
      For n = 1 To 101
       MSFlexGrid1.TextMatrix(n, 0) = n
       Next n
End Sub
Sub ShowTextBox()

        With MSFlexGrid1

         '隐藏文本框,设置高度和宽度

         text1.Visible = False

         text1.Height = .RowHeight(.Row) - (Screen.TwipsPerPixelY) * 2

         text1.Width = .ColWidth(.Col)

        ' 计算文本框左坐标

         text1.Left = .CellLeft + .Left

         text1.Top = .CellTop + .Top

         text1.Visible = True

         text1.SetFocus

     End With

    End Sub

    '当有按键触发网格单元时,则把单元中的内容保存到文本框中,然后显示文本框等待编辑。

    Private Sub MSFlexGrid1_KeyPress(KeyAscii As Integer)

    Dim char As String

    If KeyAscii = 13 Then

     text1.Text = MSFlexGrid1.Text

         text1.SelStart = Len(text1.Text)

         Else

            char = Chr$(KeyAscii)

            text1.Text = char

            text1.SelStart = 1

         End If

         ShowTextBox

         KeyAscii = 0

    End Sub

    '当焦点离开一个网格单元时,先保存文本框中的内容到网格单元,然后检测离开单元是否在最大行第一列(可自己设第几列),如果是自动加一行。

    Private Sub MSFlexGrid1_LeaveCell()

        MSFlexGrid1.Text = text1.Text

    If MSFlexGrid1.Col = 0 And MSFlexGrid1.Row <> 0 And MSFlexGrid1.Row = MSFlexGrid1.Rows - 1 And MSFlexGrid1.Text <> "" Then

         MSFlexGrid1.Rows = MSFlexGrid1.Rows + 1

     End If

    End Sub

        '为了响应鼠标动作,添加以下代码。

    Private Sub MSFlexGrid1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)

     text1.Visible = False

    End Sub

        '当网格单元发生变化时,取网格单元内容到文本框,等待编辑,从而保证文本框中的内容最新。

    Private Sub MSFlexGrid1_RowColChange()

     text1.Text = MSFlexGrid1.Text

    End Sub

    '双击网格单元可以对网格单元中内容进行编辑?

    Private Sub MSFlexGrid1_DblClick()

     If MSFlexGrid1.Row > 0 And MSFlexGrid1.Col = 0 Then MSFlexGrid1_KeyPress 13

    End Sub

    '文本框起输入编辑框的作用,模拟网格单元,输入到文本框的内容,经过处理送到网格中,当输入完后按回车键可以自动到下一列,若为最后一列,跳转到下一行的第一列等待输入。

    Private Sub Text1_KeyPress(KeyAscii As Integer)

        If KeyAscii = 13 Then

            MSFlexGrid1.Text = text1.Text

            text1.Visible = False

            MSFlexGrid1.SetFocus

            If MSFlexGrid1.Col < (MSFlexGrid1.Cols - 1) Then

             MSFlexGrid1.Col = MSFlexGrid1.Col + 1

            ElseIf MSFlexGrid1.Row < MSFlexGrid1.Rows - 1 Then

                 MSFlexGrid1.Row = MSFlexGrid1.Row + 1

                 MSFlexGrid1.Col = 0

            End If

            KeyAscii = 0

         End If

    End Sub

Private Sub Form_Resize()
 MSFlexGrid1.Height = ScaleHeight
  MSFlexGrid1.Width = ScaleWidth
End Sub

Sub dk()
CommonDialog1.Filter = "rtf文件(*.rtf)|*.rtf" & "|所有文件(*.*)*.*"
CommonDialog1.FileName = ""
CommonDialog1.FilterIndex = 0
CommonDialog1.ShowOpen
If Len(CommonDialog1.FileName) = 0 Then
Exit Sub
End If
FileName = CommonDialog1.FileName
If CommonDialog1.FilterIndex = 1 Then
text1.LoadFile CommonDialog1.FileName, rtfRTF

End If
End Sub
Sub bc()
CommonDialog1.Filter = "rtf文件(*.rtf)|.rtf" & "|所有文件(*.*)|*.*"
CommonDialog1.FileName = FileName
CommonDialog1.ShowSave
If Len(CommonDialog1.FileName) = 0 Then
Exit Sub
End If
If CommonDialog1.FilterIndex = 1 Then
text1.SaveFile CommonDialog1.FileName, rtfRTF

End If
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -