📄 form1.vb
字号:
'
'axFramer2
'
Me.axFramer2.ContainingControl = Me
Me.axFramer2.Dock = System.Windows.Forms.DockStyle.Fill
Me.axFramer2.Enabled = True
Me.axFramer2.Location = New System.Drawing.Point(0, 0)
Me.axFramer2.Name = "axFramer2"
Me.axFramer2.OcxState = CType(resources.GetObject("axFramer2.OcxState"), System.Windows.Forms.AxHost.State)
Me.axFramer2.Size = New System.Drawing.Size(564, 451)
Me.axFramer2.TabIndex = 0
'
'tbDoc3
'
Me.tbDoc3.Controls.Add(Me.axFramer3)
Me.tbDoc3.Location = New System.Drawing.Point(4, 22)
Me.tbDoc3.Name = "tbDoc3"
Me.tbDoc3.Size = New System.Drawing.Size(564, 451)
Me.tbDoc3.TabIndex = 0
Me.tbDoc3.Tag = 3
Me.tbDoc3.Text = "Document3"
'
'axFramer3
'
Me.axFramer3.ContainingControl = Me
Me.axFramer3.Dock = System.Windows.Forms.DockStyle.Fill
Me.axFramer3.Enabled = True
Me.axFramer3.Location = New System.Drawing.Point(0, 0)
Me.axFramer3.Name = "axFramer3"
Me.axFramer3.OcxState = CType(resources.GetObject("axFramer3.OcxState"), System.Windows.Forms.AxHost.State)
Me.axFramer3.Size = New System.Drawing.Size(564, 451)
Me.axFramer3.TabIndex = 0
'
'OFileDialog
'
Me.OFileDialog.Filter = "Microsoft Office Files|*.doc;*.docx;*.docm;*.xls;*.xlsx;*.xlsm;*.xlsb;*.ppt;*.ppt" & _
"x;*.pptm|All Files|*.*"
'
'FTestApp
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(572, 510)
Me.Controls.Add(Me.tbcDocsCont)
Me.Controls.Add(Me.picLogo)
Me.Controls.Add(Me.panTitlebar)
Me.MinimumSize = New System.Drawing.Size(580, 500)
Me.Name = "FTestApp"
Me.Text = "DsoFramer VB7 Sample Application"
Me.panTitlebar.ResumeLayout(False)
Me.tbcDocsCont.ResumeLayout(False)
Me.tbMain.ResumeLayout(False)
Me.gboxOpen.ResumeLayout(False)
Me.gboxCreate.ResumeLayout(False)
Me.tbDoc4.ResumeLayout(False)
CType(Me.axFramer4, System.ComponentModel.ISupportInitialize).EndInit()
Me.tbDoc1.ResumeLayout(False)
CType(Me.axFramer1, System.ComponentModel.ISupportInitialize).EndInit()
Me.tbDoc2.ResumeLayout(False)
CType(Me.axFramer2, System.ComponentModel.ISupportInitialize).EndInit()
Me.tbDoc3.ResumeLayout(False)
CType(Me.axFramer3, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
Dim m_iCounter As Integer
Dim m_bFilesOpen(4) As Boolean
' ============================================================================
' GetOpenSlot - Helper Function
'
' Returns free slot for tab page and framer control. You could implement a
' a dynamic control array and support up to the max number of framer controls,
' but we are keeping this simple and limiting to just 4 open docs at a time.
'
' ============================================================================
Private Function GetOpenSlot() As Integer
Dim i As Integer
For i = 0 To 3
If m_bFilesOpen(i) = False Then
Return i + 1
End If
Next
Return 0
End Function
' ============================================================================
' GetTabPageFromIdx - Helper Function
'
' Returns tab page control for the given slot.
'
' ============================================================================
Private Function GetTabPageFromIdx(ByVal idx As Integer) As TabPage
Select Case idx
Case 1
Return Me.tbDoc1
Case 2
Return Me.tbDoc2
Case 3
Return Me.tbDoc3
Case 4
Return Me.tbDoc4
Case Else
Throw New Exception("Invalid Index")
End Select
End Function
' ============================================================================
' GetFramerCtlFromIdx - Helper Function
'
' Returns DsoFramer control for the given slot.
'
' ============================================================================
Private Function GetFramerCtlFromIdx(ByVal idx As Integer) As AxDSOFramer.AxFramerControl
Select Case idx
Case 1
Return Me.axFramer1
Case 2
Return Me.axFramer2
Case 3
Return Me.axFramer3
Case 4
Return Me.axFramer4
Case Else
Throw New Exception("Invalid Index")
End Select
End Function
' ============================================================================
' AddTabAndActivate - Helper Subroutine
'
' Adds tab page to the TabControl on our main form, and sets a default name
' for the tab (assuming this is new document). Then selects the tab to activate.
'
' ============================================================================
Private Sub AddTabAndActivate(ByVal idx As Integer)
Dim tab As TabPage
Dim axControl As AxDSOFramer.AxFramerControl
m_iCounter = m_iCounter + 1
' Get the tab control and add it to the collection...
tab = GetTabPageFromIdx(idx)
tab.Text = "New Document " & m_iCounter
Me.tbcDocsCont.Controls.Add(tab)
Me.tbcDocsCont.SelectedTab = tab
' Get the Framer control and set some default properties since
' we don't want user to open/new without going to our main tab.
axControl = GetFramerCtlFromIdx(idx)
axControl.set_EnableFileCommand(DSOFramer.dsoFileCommandType.dsoFileNew, False)
axControl.set_EnableFileCommand(DSOFramer.dsoFileCommandType.dsoFileOpen, False)
' We need to explicitly enable the event sinks. Due to a strange bug in .NET
' when the control is sited to tab page and not the main form, it is told to
' freeze events (IOleControl) but never told to unfreeze. So events don't get
' fired correctly from tab strip. This sets the flag to re-enable the events.
axControl.EventsEnabled = True
axControl.Select()
' Since we just activated, mark this slot as occupied...
m_bFilesOpen(idx - 1) = True
End Sub
' ============================================================================
' RemoveTabAndSelectMain - Helper Subroutine
'
' Removes the tab from the collection when the document is closed by user.
'
' ============================================================================
Private Sub RemoveTabAndSelectMain(ByVal idx As Integer)
Me.tbcDocsCont.Controls.Remove(GetTabPageFromIdx(idx))
Me.tbcDocsCont.SelectedIndex = 1
m_bFilesOpen(idx - 1) = False
End Sub
' ============================================================================
' btnOpenFile_Click - File Open Button Click Handler
'
' Opens the file in DsoFramer control and appends it to a new tab in the
' tab strip control. We allow user to pick the file using File Open dialog.
'
' ============================================================================
Private Sub btnOpenFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpenFile.Click
' Ensure we have a free slot...
Dim idx As Integer = GetOpenSlot()
If idx = 0 Then
MessageBox.Show("You can only have four documents open at a time. Close will need to close one to continue.", "Open File", _
MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Exit Sub
End If
' Temporarily disable the buttons so we don't re-enter
btnCreateNew.Enabled = False
btnOpenFile.Enabled = False
' Ask user for the file to open...
Dim r As DialogResult = OFileDialog.ShowDialog()
If r = DialogResult.OK Then
' Add the tab to the collection and switch to the tab...
AddTabAndActivate(idx)
' Get the framer control for that slot...
Dim ctl As AxDSOFramer.AxFramerControl
ctl = GetFramerCtlFromIdx(idx)
Try
' Ask it to open the file...
ctl.Open(OFileDialog.FileName)
' Get the tab page and change the title to the name of the file opened...
Dim tp As TabPage
tp = GetTabPageFromIdx(idx)
tp.Text = ctl.DocumentName
Catch ex As Exception
' Show the error to user...
MessageBox.Show("Unable to open the file. " & ex.Message, "File Open", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
' If we fail, remove the tab and take us back to the main page
RemoveTabAndSelectMain(idx)
End Try
End If
btnCreateNew.Enabled = True
btnOpenFile.Enabled = True
End Sub
' ============================================================================
' btnCreateNew_Click - Create New Button Click Handler
'
' Creates new blank document of one of the types selected in Radio buttons.
'
' ============================================================================
Private Sub btnCreateNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreateNew.Click
' Ensure we have a free slot...
Dim idx As Integer = GetOpenSlot()
If idx = 0 Then
MessageBox.Show("You can only have four documents open at a time. Close will need to close one to continue.", "Create New", _
MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Exit Sub
End If
' Temporarily disable the buttons so we don't re-enter
btnCreateNew.Enabled = False
btnOpenFile.Enabled = False
' Pick the ProgID from the Radio button selected...
Dim sProgID As String
If rbtnNewWord.Checked Then
sProgID = "Word.Document.8"
ElseIf rbtnNewExcel.Checked Then
sProgID = "Excel.Sheet.8"
Else
sProgID = "PowerPoint.Show.8"
End If
' Add the tab page to tab and make it visible...
AddTabAndActivate(idx)
' Get the framer control for that free slot...
Dim ctl As AxDSOFramer.AxFramerControl
ctl = GetFramerCtlFromIdx(idx)
Try
' Ask it to create the new object...
ctl.CreateNew(sProgID)
Catch ex As Exception
' Show error to user...
MessageBox.Show("Unable to create the new document. " & ex.Message, "Create New", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
' If we fail, remove the tab and take us back to the main page
RemoveTabAndSelectMain(idx)
End Try
btnCreateNew.Enabled = True
btnOpenFile.Enabled = True
End Sub
' ============================================================================
' tbcDocsCont_SelectedIndexChanged
'
' When switching tabs, activate the framer control associated with that tab.
'
' ============================================================================
Private Sub tbcDocsCont_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles tbcDocsCont.SelectedIndexChanged
Dim tab As TabPage = tbcDocsCont.SelectedTab
Dim framer As AxDSOFramer.AxFramerControl
Dim idx As Integer = tab.Tag
If (idx >= 1 And idx <= 4) Then
framer = GetFramerCtlFromIdx(idx)
framer.Activate()
End If
End Sub
' ============================================================================
' axFramerX_OnDocumentClosed
'
' Control event handlers to remove the tab when the document(s) are closed.
'
' ============================================================================
Private Sub axFramer1_OnDocumentClosed(ByVal sender As Object, ByVal e As System.EventArgs) Handles axFramer1.OnDocumentClosed
RemoveTabAndSelectMain(1)
End Sub
Private Sub axFramer2_OnDocumentClosed(ByVal sender As Object, ByVal e As System.EventArgs) Handles axFramer2.OnDocumentClosed
RemoveTabAndSelectMain(2)
End Sub
Private Sub axFramer3_OnDocumentClosed(ByVal sender As Object, ByVal e As System.EventArgs) Handles axFramer3.OnDocumentClosed
RemoveTabAndSelectMain(3)
End Sub
Private Sub axFramer4_OnDocumentClosed(ByVal sender As Object, ByVal e As System.EventArgs) Handles axFramer4.OnDocumentClosed
RemoveTabAndSelectMain(4)
End Sub
' ============================================================================
' axFramerX_OnSaveCompleted
'
' Control event handlers to rename tabs if document is saved by a new name.
'
' ============================================================================
Private Sub axFramer1_OnSaveCompleted(ByVal sender As Object, ByVal e As AxDSOFramer._DFramerCtlEvents_OnSaveCompletedEvent) Handles axFramer1.OnSaveCompleted
Dim s As String = e.docName
If s.Length > 1 Then tbDoc1.Text = e.docName
End Sub
Private Sub axFramer2_OnSaveCompleted(ByVal sender As Object, ByVal e As AxDSOFramer._DFramerCtlEvents_OnSaveCompletedEvent) Handles axFramer2.OnSaveCompleted
Dim s As String = e.docName
If s.Length > 1 Then tbDoc2.Text = e.docName
End Sub
Private Sub axFramer3_OnSaveCompleted(ByVal sender As Object, ByVal e As AxDSOFramer._DFramerCtlEvents_OnSaveCompletedEvent) Handles axFramer3.OnSaveCompleted
Dim s As String = e.docName
If s.Length > 1 Then tbDoc3.Text = e.docName
End Sub
Private Sub axFramer4_OnSaveCompleted(ByVal sender As Object, ByVal e As AxDSOFramer._DFramerCtlEvents_OnSaveCompletedEvent) Handles axFramer4.OnSaveCompleted
Dim s As String = e.docName
If s.Length > 1 Then tbDoc4.Text = e.docName
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -