Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your <code>Speak</code> method could return the process it's started:</p> <pre><code>public Process Speak() { // Code as before return process1; } </code></pre> <p>Then you can write:</p> <pre><code>private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { TextToSpeech obj = new TextToSpeech(); Process process = obj.Speak(); process.Kill(); } </code></pre> <p>If you want to actually start the process in one event and kill it in another, you'll probably want an instance variable in your form which maintains the last-started process:</p> <pre><code>private Process speechProcess; private void StartButtonClicked(object sender, EventArgs e) { // TODO: consider what you want to happen if there's already // a process running TextToSpeech obj = new TextToSpeech(); speechProcess = obj.Speak(); } private void StopButtonClicked(object sender, EventArgs e) { // Possibly change the UI so that the button will be disabled // when there's no process running if (speechProcess == null) { return; } speechProcess.Kill(); speechProcess = null; } </code></pre> <p>EDIT: As noted in comments, this ties the <code>TextToSpeech</code> class to the idea of using a process. It would be provide better encapsulation if you made <code>TextToSpeech</code> responsible for the process management, so you could ask that to start and stop appropriately. Then you'd change the <code>speechProcess</code> variable above from a <code>Process</code> type variable to <code>TextToSpeech</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload