frmdocument.frm

来自「主要用于学校机房考试,主要包括选择题,问答题,WORD操作题,WINDOWS操作」· FRM 代码 · 共 186 行

FRM
186
字号
VERSION 5.00
Object = "{D3439CBA-E2C3-11D3-8C5C-00001C531F9C}#2.0#0"; "chinaexcel.ocx"
Begin VB.Form frmDocument 
   Caption         =   "frmDocument"
   ClientHeight    =   3195
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4680
   Icon            =   "frmDocument.frx":0000
   LinkTopic       =   "Form1"
   MDIChild        =   -1  'True
   ScaleHeight     =   3195
   ScaleWidth      =   4680
   WindowState     =   2  'Maximized
   Begin ChinaExcelLib.ChinaExcel Formvw1 
      Height          =   2895
      Left            =   0
      TabIndex        =   3
      Top             =   360
      Width           =   4695
      _Version        =   131072
      _ExtentX        =   8281
      _ExtentY        =   5106
      _StockProps     =   0
   End
   Begin VB.ComboBox ComboCellName 
      Height          =   315
      Left            =   0
      TabIndex        =   1
      Text            =   "A1"
      Top             =   0
      Width           =   1215
   End
   Begin VB.TextBox CellEdit 
      Height          =   285
      Left            =   2160
      TabIndex        =   0
      Top             =   0
      Width           =   3735
   End
   Begin VB.Label LabelEdit 
      Alignment       =   2  'Center
      Caption         =   "输入框"
      Height          =   200
      Left            =   1200
      TabIndex        =   2
      Top             =   0
      Width           =   855
   End
End
Attribute VB_Name = "frmDocument"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim g_bCellEdit

Private Sub CellEdit_Change()
    If g_bCellEdit Then
        Formvw1.SetEditLineText (CellEdit.Text)
        Formvw1.GetFocus
    End If
End Sub

Private Sub CellEdit_GotFocus()
    g_bCellEdit = True
End Sub

Private Sub CellEdit_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyReturn Then
        Formvw1.EndCellEdit (True)
        Formvw1.GetFocus
    Else
        If KeyCode = vbKeyCancel Then
            Formvw1.EndCellEdit (False)
            Formvw1.GetFocus
        End If
    End If
End Sub

Private Sub CellEdit_LostFocus()
    g_bCellEdit = False
End Sub

Private Sub ComboCellName_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyReturn Then
        Formvw1.GoToCellName (ComboCellName.Text)
    End If
End Sub

Private Sub Form_Activate()
    fMainForm.mnuShowHeader.Checked = Formvw1.ShowHeader
    fMainForm.mnuShowGrid.Checked = Formvw1.ShowGrid
    fMainForm.mnuShowErrMsgBox.Checked = Formvw1.ShowErrorMsgBox
    fMainForm.mnuFormProtect.Checked = Formvw1.FormProtect
    fMainForm.mnuDesignMode.Checked = Formvw1.DesignMode
    If Formvw1.GetRowLabel() = 0 Then
        fMainForm.mnuSetRowLabel.Checked = False
    Else
        fMainForm.mnuSetRowLabel.Checked = True
    End If
    If Formvw1.GetColLabel() = 0 Then
        fMainForm.mnuSetColLabel.Checked = False
    Else
        fMainForm.mnuSetColLabel.Checked = True
    End If
End Sub

Private Sub Form_Load()
    Form_Resize
    g_bCellEdit = True
End Sub


Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    If Formvw1.IsModified Then
        Dim Msg, Style, Title, Response
        Msg = "'" + fMainForm.ActiveForm.Caption + "'已经被修改,是否保存该文件?(是/不是)" ' 定义信息。
        Style = vbYesNoCancel + vbQuestion + vbDefaultButton1   ' 定义按钮。
        Title = "关闭窗口提示"   ' 定义标题。
        Response = MsgBox(Msg, Style, Title)
        If Response = vbYes Then   ' 用户按下“是”。
            If Left$(fMainForm.ActiveForm.Caption, 2) = "表格" Then
                fMainForm.ActiveForm.Formvw1.OnFileSave
            Else
                fMainForm.ActiveForm.Formvw1.SaveFile (fMainForm.ActiveForm.Caption)
            End If
        Else
            If Response = vbCancel Then
                Cancel = True
            End If
        End If
    End If
End Sub

Private Sub Form_Resize()
    On Error Resume Next
    ComboCellName.Move 0, 0, ComboCellName.Width, ComboCellName.Height
    CellEdit.Move LabelEdit.Left + LabelEdit.Width + 1, 0, Me.ScaleWidth - LabelEdit.Width - ComboCellName.Width, ComboCellName.Height
    Formvw1.Move 0, ComboCellName.Height + 2, Me.ScaleWidth, Me.ScaleHeight - ComboCellName.Height - 2
    Formvw1.RightMargin = Formvw1.Width
'    Formvw1.Move 100, 100, Me.ScaleWidth - 200, Me.ScaleHeight - 200
'    Formvw1.RightMargin = Formvw1.Width - 400
End Sub


Private Sub Formvw1_EditCellChanged(ByVal Row As Long, ByVal Col As Long)
    g_bCellEdit = False
    CellEdit.Text = Formvw1.GetEditLineText
End Sub

Private Sub Formvw1_SelectRegion(ByVal StartRow As Long, ByVal StartCol As Long, ByVal EndRow As Long, ByVal EndCol As Long)
    If StartRow = EndRow And StartCol = EndCol Then
        ComboCellName.Text = Formvw1.GetCellName(StartRow, StartCol)
    Else
        ComboCellName.Text = Formvw1.GetCellName(StartRow, StartCol) & " X " & Formvw1.GetCellName(EndRow, EndCol)
    End If
    Formvw1.GetFocus
End Sub

Private Sub Formvw1_ShowCellChanged(ByVal Row As Long, ByVal Col As Long)
    fMainForm.tbToolBar.Buttons("Horz Left").Value = IIf(Formvw1.HorzTextAlign = 1, tbrPressed, tbrUpressed)
    fMainForm.tbToolBar.Buttons("Horz Center").Value = IIf(Formvw1.HorzTextAlign = 2, tbrPressed, tbrUpressed)
    fMainForm.tbToolBar.Buttons("Horz Right").Value = IIf(Formvw1.HorzTextAlign = 3, tbrPressed, tbrUpressed)
    fMainForm.tbToolBar.Buttons("Vert Top").Value = IIf(Formvw1.VertTextAlign = 1, tbrPressed, tbrUpressed)
    fMainForm.tbToolBar.Buttons("Vert Center").Value = IIf(Formvw1.VertTextAlign = 2, tbrPressed, tbrUpressed)
    fMainForm.tbToolBar.Buttons("Vert Bottom").Value = IIf(Formvw1.VertTextAlign = 3, tbrPressed, tbrUpressed)
    fMainForm.tbToolBar.Buttons("Bold").Value = IIf(Formvw1.Bold, tbrPressed, tbrUnpressed)
    fMainForm.tbToolBar.Buttons("Italic").Value = IIf(Formvw1.Italic, tbrPressed, tbrUnpressed)
    fMainForm.tbToolBar.Buttons("Underline").Value = IIf(Formvw1.Underline, tbrPressed, tbrUnpressed)
  
    fMainForm.mnuAutoWrap.Checked = Formvw1.AutoWrap
    
    ComboCellName.Text = Formvw1.GetCellName(Row, Col)
    g_bCellEdit = False
    CellEdit.Text = ""
    CellEdit.Text = Formvw1.GetCellFormula(Row, Col)
    If CellEdit.Text = "" Then
        CellEdit.Text = Formvw1.GetCellValue(Row, Col)
    End If
    fMainForm.ComboFontSize.Text = Formvw1.CellFontSize
'    fMainForm.ComboFontName.Text = Formvw1.CellFontName
    Formvw1.GetFocus
End Sub

⌨️ 快捷键说明

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