怎样向VBIDE中添加工具窗体?
首先请创建一个用户文档.设置属性ContinuousScroll 为假 ,ScrollBars为0 在窗体中添加你所需要的控件以及在代码中添加你所需要的代码.
以下代码实现了标签定位功能.即CoderHelper 的标签管理器!你需要添加一个名字为lstTag的列表框控件.
Option Explicit
Private Sub lstTag_DblClick()
On Error Resume Next
Dim cm As CodeModule
Set cm = MVBI.SelectedVBComponent.CodeModule
Dim n As Long, n1 As Long, n2 As Long, n3 As Long
If lstTag.ListCount = 0 Then
Me.reftag MVBI.ActiveCodePane.CodeModule
Exit Sub
End If
If cm.Find("'>" + lstTag.Text + "<", n, n1, n2, n3) Then
cm.CodePane.Window.SetFocus
cm.CodePane.SetSelection n, n1, n2, n3
cm.CodePane.TopLine = n
cm.CodePane.Window.SetFocus
DoEvents
Else
WriteLine "无法查找标签[" + lstTag.Text + "],请确保格式为: '>标签名称< ", vbRed
End If
End Sub
Private Sub lstTag_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 And Shift = 1 Then
Me.reftag MVBI.SelectedVBComponent.CodeModule
End If
End Sub
Private Sub UserDocument_Resize()
On Error Resume Next
lstTag.Top = 0
lstTag.Left = 0
lstTag.Width = UserDocument.Width
lstTag.Height = UserDocument.Height
End Sub
Public Sub show()
gwinTag.Visible = True
End Sub
Public Sub hide()
gwinTag.Visible = False
End Sub
Public Sub reftag(cm As CodeModule)
Dim Tmp, ary() As String, tx As String
On Error Resume Next
tx = cm.Lines(1, cm.CountOfLines)
ary = Split(tx, "'>")
Dim lc1 As Long, lc2 As Long
lstTag.Clear
For Each Tmp In ary
If Left(Tmp, 1) <> "'" Then
lc1 = InStr(Tmp, "<")
lc2 = InStr(Tmp, " ")
If lc1 < lc2 And lc1 > 0 Then
lstTag.AddItem Mid(Tmp, 1, InStr(Tmp, "<") - 1)
End If
End If
Next
Dim tbx As String
If lstTag.ListCount = 0 Then
tbx = "该代码模块中没有添加标签,要添加请按此格式:" + vbNewLine + "'>标签名称< "
Else
tbx = "标签管理器-目前[" + cm.Parent.Name + "]拥有有效标签" & lstTag.ListCount & "个, 更新时间:" & Time
End If
lstTag.ToolTipText = tbx
WriteLine tbx, vbBlue
End Sub
接着你需要在模块中添加
Public gTag As ucTag
Public gwinTag As VBIDE.Window '承载gTag的窗体.
在加载程序中,你可以添加以下代码.
WriteLine "创建并配置标签窗口." & Timer, vbBlue
Set gwinTag = VBI.Windows.CreateToolWindow(aitmp, App.ProductName + ".ucTag", "标签管理器", "T_a_g_M_a_n_a_g_e_r", gTag)
Set TAg = AddToMenu("刷新/显示标签", MyFunName, 459)'把事件吸取到工具条MyFunName中.图标的资源位置为 459号图片!
aitmp是本插件的名称.