Использование bash (cygwin) внутри программы на C #

Мне не удалось выделить / выделить текст в событии Enter, поскольку события mousedown и mouseup, следующие после этого, несколько сбрасывают выбор.

Я думаю, что самый правильный способ добиться того, что вы хотите это:

' if you want to allow highlight more then once, reset the  variable LastEntered prior to call SelectTboxText:
'       LastEntered = ""
'       SelectTboxText TextBox2


Dim LastEntered As String


' Button to select Textbox1
Private Sub CommandButton1_Click()
    SelectTboxText TextBox1
End Sub

' Button to select Textbox2
Private Sub CommandButton2_Click()
    SelectTboxText TextBox2
End Sub

Private Sub TextBox1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    SelectTboxText TextBox1
End Sub


Private Sub TextBox2_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
     SelectTboxText TextBox2
End Sub


Public Sub SelectTboxText(ByRef tBox As MSForms.TextBox)

    If LastEntered <> tBox.Name Then

        LastEntered = tBox.Name

        With tBox
            .SetFocus
            .SelStart = 0
            .SelLength = Len(.Text)
        End With

    End If

End Sub

Итак, каждый раз, когда вы хотите программно активировать одно из текстового поля, вы должны вызвать sub SelectTboxText, что на самом деле не раздражает IMO. Я сделал 2 кнопки для этого в качестве примера.

21
задан Douglas Leeder 20 September 2009 в 10:40
поделиться

1 ответ

A side note, not a real answer, have a look at: http://www.codeproject.com/KB/IP/sharpssh.aspx

To answer the question:

Your not correctly handling the events... You need to look for e.Data == null in the event handler for Error/Output received. Once both event handlers receive this event AND the process has terminated you are done. Thus you wait on three handles, one to tell you the Process.Exited event fired, one to tell you the error output received null, one to tell you the output received null. Be sure to also set:

process.EnableRaisingEvents = true;

Here is the full answer redirecting output to current console:

    static int RunProgram(string exe, params string[] args)
    {
        ManualResetEvent mreProcessExit = new ManualResetEvent(false);
        ManualResetEvent mreOutputDone = new ManualResetEvent(false);
        ManualResetEvent mreErrorDone = new ManualResetEvent(false);

        ProcessStartInfo psi = new ProcessStartInfo(exe, String.Join(" ", args));
        psi.WorkingDirectory = Environment.CurrentDirectory;

        psi.RedirectStandardError = true;
        psi.RedirectStandardOutput = true;
        psi.CreateNoWindow = true;
        psi.UseShellExecute = false;
        psi.ErrorDialog = true;

        Process process = new Process();
        process.StartInfo = psi;

        process.Exited += delegate(object o, EventArgs e)
        {
            Console.WriteLine("Exited.");
            mreProcessExit.Set();
        };
        process.OutputDataReceived += delegate(object o, DataReceivedEventArgs e) 
        {
            if( e.Data != null )
                Console.WriteLine("Output: {0}", e.Data); 
            else
                mreOutputDone.Set(); 
        };
        process.ErrorDataReceived += delegate(object o, DataReceivedEventArgs e)
        {
            if (e.Data != null)
                Console.Error.WriteLine("Error: {0}", e.Data);
            else
                mreErrorDone.Set();
        };

        process.EnableRaisingEvents = true;
        Console.WriteLine("Start: {0}", process.StartInfo.FileName); 
        process.Start();
        process.BeginErrorReadLine();
        process.BeginOutputReadLine();

        if (process.HasExited) 
            mreProcessExit.Set();

        while(!WaitHandle.WaitAll(new WaitHandle[] { mreErrorDone, mreOutputDone, mreProcessExit }, 100))
            continue;
        return process.ExitCode;
    }
2
ответ дан 29 November 2019 в 22:13
поделиться
Другие вопросы по тегам:

Похожие вопросы: