2

我正在构建一个从对象模型中提取脚本的程序。现在我的脚本进入一个文本框,然后单击按钮,我将它保存到一个临时文件,然后用记事本++打开该临时文件。它可以工作并且有目的,但我希望在我的表单中打开记事本++,以使其更加无缝。

有没有办法做到这一点?

这是我当前的代码:

System.IO.File.WriteAllText("c:temp\script.txt", textBox1.Text)
Process.Start("c:program files(86)\notepad++\notepad++.exe", "c:temp\script.txt")

任何帮助或建议都会很棒!

4

2 回答 2

3

有没有办法做到这一点?

您不能将程序Notepad++直接嵌入到您的表单中。但是,您可以使用ScintillaNET直接在程序中添加编辑器。 ScintillaNET是基于Scintilla,这是 Notepad++ 和许多其他软件产品使用的底层代码。

于 2013-09-02T20:32:46.623 回答
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
于 2019-09-09T17:13:32.427 回答