1. 下载一个nodepad++放在D盘下(放其它地方也行,改一下后面的代码就是了),然后在Notepad++的视图菜单下点击自定义语言格式,在里面新建一个语言,名称为Foxtable,后缀设置为Fox,各项设置去语言设计里面找一下vb的复制过来,然后其它的根据个人喜好修改好(这里不多介绍,具体百度一下Notepad++的用法)
2. 在计划管理新建一个计划(用于在编辑器上面创建按钮),名称为编辑器按钮,间隔300毫秒,代码如下:
Dim frmCodeEditor As Windows.Forms.Form = Windows.Forms.Form.ActiveForm
If frmCodeEditor Is Nothing Then Return
If frmCodeEditor.Name <> "frmCommand" And frmCodeEditor.Name <> "frmCodeEditor" Then Return
If frmCodeEditor.Controls("BtnNotepadEdit") IsNot Nothing Then Return
Dim BtnFind As Windows.Forms.Button = frmCodeEditor.Controls("Button4")
Dim BtnNotepadEdit As New Windows.Forms.Button
With BtnNotepadEdit
.Name = "BtnNotepadEdit"
.Anchor = windows.Forms.AnchorStyles.Left Or windows.Forms.AnchorStyles.Bottom
.Top = BtnFind.Top
.Left = 96
.Size = BtnFind.Size
.Text = "NotePad++"
AddHandler .Click,AddressOf NotepadEdit_Click
End With
frmCodeEditor.Controls.Add(BtnNotepadEdit)
3. 新增一个内部函数,名称为NodePadEdit,代码如下:
'调用Notepad++
Dim CodeBox As Windows.Forms.RichTextBox = CodeRichTextBox
FileSys.WriteAllText(ProjectPath & "Temp\Code.Fox",CodeRichTextBox.Text,False)
CodeRichTextBox.SelectAll
Dim Proc As New Process
Proc.WaitForClose = True
Proc.File = "D:\Notepad++\notepad++.exe "
Proc.Arguments = ProjectPath & "Temp\Code.Fox"
Proc.Start
Dim CodeStr As String = FileSys.ReadAllText(ProjectPath & "Temp\Code.Fox")
If CodeStr = CodeBox.Text Then Return Nothing
CodeBox.Text = CodeStr
4. 在全局代码中加入以下代码:
'此函数用于返回代码编辑器的RichTextBox控件
Public Function CodeRichTextBox() As Windows.Forms.RichTextBox
Dim frmCodeEditor As Windows.Forms.Form = Windows.Forms.Form.ActiveForm
If frmCodeEditor Is Nothing Then Return Nothing
If frmCodeEditor.Name <> "frmCommand" And frmCodeEditor.Name <> "frmCodeEditor" Then Return Nothing
Dim SplitCtl As Windows.Forms.SplitContainer
If frmCodeEditor.Name = "frmCommand" Then
SplitCtl = frmCodeEditor.Controls("SplitContainer1")
SplitCtl = SplitCtl.Panel1.Controls("MyCodeEditor21").Controls("SplitContainer1")
Else
SplitCtl = frmCodeEditor.Controls("MyCodeEditor1").Controls("SplitContainer1")
End If
SplitCtl = SplitCtl.Panel1.Controls("SplitContainer2")
Dim RichTextBox As Windows.Forms.RichTextBox = SplitCtl.PaneL1.Controls("Editor")
Return RichTextBox
End Function
'启动NotePad++
Public Sub NotepadEdit_Click(ByVal sender As Object, ByVal e As EventArgs)
Function.ecute("NodePadEdit")
End Sub
重启项目之后打开命令窗口或者代码编辑器就会发现下面多出一个按钮,点击之后就可以在notepad++中编辑代码了