Now in the groupbox i added a checkbox and what i wanted to do is when its checked it will activate voices on my program i mean SpeechSynthesiz er()
And its working when i check in the checkbox it says "Voices are now enabled" and when uncheck it says " Voices now disabled".
The problem is im using on my form1 in few places from the new form to hear voices and when i check in the checkbox on the new form and it says " Voices are now enabled" if im doing it in runtime when my program is running i need to exit the program run it again and only then it will take effect on the voices in form1. And if i disable the voices in the new form uncheck the box it will say the voices disabled but they will still be enabled only if ill exit the program and run it again it will take effect and will be disabled.
My problem how to make it so if i change the checkbox in runtime it will take effect on form1 in runtime? Without exiting the program all the time.
Here is the code on the new form:
Expand|Select|Wrap|Line Numbers
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Net;
- using System.IO;
- using AboutIt;
- using General_utility;
- using DannyGeneral;
- using System.Runtime.InteropServices;
- using System.Diagnostics;
- using System.Threading;
- using System.Net.NetworkInformation;
- using statistic;
- using ZedGraph;
- using System.Management;
- using System.Security;
- using System.Security.AccessControl;
- using System.Security.Principal;
- using System.Net.Mail;
- using System.Net.Mime;
- using Microsoft.Win32;
- using System.Web;
- using MyWebBrowser;
- using System.Speech.Synthesis;
- using System.Resources;
- using System.Reflection;
- using System.Globalization;
- namespace WindowsFormsApplication1
- {
- public partial class SettingsMenu : Form
- {
- public bool voices_on_off;
- string path_exe;
- string settings_dir;
- string settings_file;
- OptionsFile setting_file;
- public SpeechSynthesizer speaker;
- public SettingsMenu()
- {
- InitializeComponent();
- voices_on_off = false;
- path_exe = Path.GetDirectoryName(Application.LocalUserAppDataPath);
- settings_file = "\\settings.txt";
- settings_dir = path_exe + @"\settings";
- setting_file = new OptionsFile(settings_dir + settings_file);
- speaker = new SpeechSynthesizer();
- groupBox1.Visible = false;
- groupBox1.Enabled = false;
- bool b = false;
- string key = setting_file.GetKey("Voices");
- if (key == null)
- {
- }
- else
- {
- bool.TryParse(key.Trim(), out b);
- EnableVoices.Checked = b;
- }
- }
- private void SettingsMenu_Load(object sender, EventArgs e)
- {
- }
- private void treeView1_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
- {
- if (treeView1.SelectedNode.Name.Equals(treeView1.Nodes["Main"].Name))
- {
- if (treeView1.SelectedNode.IsExpanded == false)
- {
- groupBox1.Visible = false;
- groupBox1.Enabled = false;
- }
- }
- if (treeView1.SelectedNode.Name.Equals(treeView1.Nodes["Main"].Name)) // Here Main is ur Parent Node Name
- {
- if (treeView1.SelectedNode.IsExpanded == true)
- {
- groupBox1.Visible = true;
- groupBox1.Enabled = true;
- }
- }
- }
- private void button1_Click(object sender, EventArgs e)
- {
- }
- private void button2_Click(object sender, EventArgs e)
- {
- }
- private void View_Log_File_Click(object sender, EventArgs e)
- {
- }
- private void SendLogFile_Click(object sender, EventArgs e)
- {
- }
- private void button8_Click(object sender, EventArgs e)
- {
- }
- private void EnableVoices_CheckedChanged(object sender, EventArgs e)
- {
- if (EnableVoices.Checked == true)
- {
- voices_on_off = true;
- speaker.Dispose();
- speaker = new SpeechSynthesizer();
- EnableVoices.Text = "Voices Are Now Enabled";
- speaker.Rate = -2;
- speaker.Volume = 100;
- speaker.SpeakAsync("Voices are now enabled");
- }
- else
- {
- this.Invoke((MethodInvoker)delegate
- {
- voices_on_off = false;
- EnableVoices.Text = "Voices Are Now Disabled";
- speaker.Dispose();
- speaker = new SpeechSynthesizer();
- speaker.SpeakAsync("voices Are Now Disabled");
- });
- }
- setting_file.SetKey("Voices", EnableVoices.Checked.ToString());
- }
- }
- }
In the form1 class level i did : SettingsMenu settingsmenu;
And in the constructor of form1 i did:
settingsmenu = new SettingsMenu();
And here is a sample line im using in my Form1 to hear the voices when cheking in the checkbox on the new form:
Expand|Select|Wrap|Line Numbers
- if (settingsmenu.voices_on_off == true)
- {
- settingsmenu.speaker.SpeakAsync("Download started");
- }
- else
- {
- }
In the new form the line setting_file.Se tKey("Voices", EnableVoices.Ch ecked.ToString( )); is where i set the key in my settings txt file so it will rmember if the checkbox checked or not. And in the new form constructor i call for this key: string key = setting_file.Ge tKey("Voices");
My problem is in runtime to take effect on the form1 changes if i check in the checkbox in the new form ill hear the voices from Form1 for example if ill click the start download button. And if i uncheck the checkbox in the new form so when i click the start download button i will not hear anything.
For now in runtime its taking effect only on the changes i did in the new form.
I tried to use the flag in the new form:
public bool voices_on_off;
But i used then a breakpoint in form1 for example on the start download button here:
if (settingsmenu.v oices_on_off == true)
But it never stoped. I checked the checkbox many times in the new form in runtime and it didnt get to the breakpoint.
Thanks for help.