我正在构建一个从对象模型中提取脚本的程序。现在我脚本进入文本框然后点击按钮我将它保存到临时文件然后用记事本++打开该临时文件。它起作用并且有用,但是我希望在我的表单中打开notepad ++以使其更加无缝。
有办法做到这一点吗?
这是我目前的代码:
System.IO.File.WriteAllText("c:temp\script.txt", textBox1.Text)
Process.Start("c:program files(86)\notepad++\notepad++.exe", "c:temp\script.txt")
任何帮助或建议都会很棒!
答案 0 :(得分:3)
有办法做到这一点吗?
您无法将Notepad++
等程序直接嵌入到表单中。但是,您可以使用ScintillaNET直接在程序中添加编辑器。 ScintillaNET
基于Scintilla
,这是Notepad ++和许多其他软件产品使用的基础代码。
答案 1 :(得分:0)
那呢!?
Imports System.ComponentModel
Imports System.Runtime.InteropServices
Public Class Form1
<DllImport("user32.dll", SetLastError:=True)>
Private Shared Function MoveWindow(hWnd As IntPtr, X As Integer, Y As Integer, nWidth As Integer, nHeight As Integer, bRepaint As Boolean) As Boolean
End Function
<DllImport("user32.dll")>
Private Shared Function SetParent(hWndChild As IntPtr, hWndNewParent As IntPtr) As IntPtr
End Function
<DllImportAttribute("user32.dll")>
Public Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
End Function
Public ENotepad As New Process()
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.DoubleBuffered = True
Notepad()
End Sub
Private Sub Form1_Closing(sender As Object, e As CancelEventArgs) Handles Me.Closing
Try
ENotepad.Kill()
Catch
End Try
End Sub
Private Sub Notepad()
ENotepad.StartInfo.FileName = "C:\Program Files\Notepad++\notepad++.exe" 'Application.StartupPath() & "\notepad++.exe"
'ENotepad.StartInfo.Arguments = ""
ENotepad.StartInfo.CreateNoWindow = True
ENotepad.StartInfo.RedirectStandardOutput = True
ENotepad.StartInfo.UseShellExecute = False
ENotepad.EnableRaisingEvents = True
'AddHandler Notepad.OutputDataReceived, Sub(o, e) Debug.WriteLine(If(e.Data, "NULL"), "Notepad")
'AddHandler Notepad.ErrorDataReceived, Sub(o, e) Debug.WriteLine(If(e.Data, "NULL"), "Notepad")
'AddHandler Notepad.Exited, Sub(o, e) Debug.WriteLine("Exited", "Notepad")
ENotepad.Start()
Thread.Sleep(1000)
Try
SetParent(ENotepad.MainWindowHandle, Me.Handle)
MoveWindow(ENotepad.MainWindowHandle, 0, 0, 320, 180, True)
'MoveWindow(ENotepad.MainWindowHandle, -5, -30, 320, 280, True)
Catch ex As Exception
Me.Text = "missed!"
End Try
End Sub
End Class