473,326 Members | 2,136 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

How to make it so if i change the checkbox in runtime it will take effect on form1?

I created a new form and added split container and then on the left side a treeview and on the treeview i added nodes and on the right side of the split container i added a groupbox.

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 SpeechSynthesizer()

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
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Net;
  10. using System.IO;
  11. using AboutIt;
  12. using General_utility;
  13. using DannyGeneral;
  14. using System.Runtime.InteropServices;
  15. using System.Diagnostics;
  16. using System.Threading;
  17. using System.Net.NetworkInformation;
  18. using statistic;
  19. using ZedGraph;
  20. using System.Management;
  21. using System.Security;
  22. using System.Security.AccessControl;
  23. using System.Security.Principal;
  24. using System.Net.Mail;
  25. using System.Net.Mime;
  26. using Microsoft.Win32;
  27. using System.Web;
  28. using MyWebBrowser;
  29. using System.Speech.Synthesis;
  30. using System.Resources;
  31. using System.Reflection;
  32. using System.Globalization;
  33.  
  34. namespace WindowsFormsApplication1
  35. {
  36.     public partial class SettingsMenu : Form
  37.     {
  38.         public bool voices_on_off;
  39.         string path_exe;
  40.         string settings_dir;
  41.         string settings_file;
  42.         OptionsFile setting_file;
  43.         public SpeechSynthesizer speaker;
  44.         public SettingsMenu()
  45.         {
  46.             InitializeComponent();
  47.             voices_on_off = false;
  48.             path_exe = Path.GetDirectoryName(Application.LocalUserAppDataPath);
  49.             settings_file = "\\settings.txt";
  50.             settings_dir = path_exe + @"\settings";
  51.             setting_file = new OptionsFile(settings_dir + settings_file);
  52.             speaker = new SpeechSynthesizer();
  53.             groupBox1.Visible = false;
  54.             groupBox1.Enabled = false;
  55.             bool b = false;
  56.             string key = setting_file.GetKey("Voices");
  57.             if (key == null)
  58.             {
  59.             }
  60.             else
  61.             {
  62.                 bool.TryParse(key.Trim(), out b);
  63.                 EnableVoices.Checked = b;
  64.             }
  65.         }
  66.  
  67.         private void SettingsMenu_Load(object sender, EventArgs e)
  68.         {
  69.  
  70.         }
  71.  
  72.         private void treeView1_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
  73.         {
  74.             if (treeView1.SelectedNode.Name.Equals(treeView1.Nodes["Main"].Name))
  75.             {
  76.                 if (treeView1.SelectedNode.IsExpanded == false)
  77.                 {
  78.                     groupBox1.Visible = false;
  79.                     groupBox1.Enabled = false;
  80.                 }
  81.             }
  82.             if (treeView1.SelectedNode.Name.Equals(treeView1.Nodes["Main"].Name))   // Here Main is ur Parent Node Name
  83.             {
  84.                 if (treeView1.SelectedNode.IsExpanded == true)
  85.                 {
  86.                     groupBox1.Visible = true;
  87.                     groupBox1.Enabled = true;
  88.                 }
  89.             }
  90.         }
  91.         private void button1_Click(object sender, EventArgs e)
  92.         {
  93.  
  94.         }
  95.  
  96.         private void button2_Click(object sender, EventArgs e)
  97.         {
  98.  
  99.         }
  100.  
  101.         private void View_Log_File_Click(object sender, EventArgs e)
  102.         {
  103.  
  104.         }
  105.  
  106.         private void SendLogFile_Click(object sender, EventArgs e)
  107.         {
  108.  
  109.         }
  110.  
  111.         private void button8_Click(object sender, EventArgs e)
  112.         {
  113.  
  114.         }
  115.  
  116.         private void EnableVoices_CheckedChanged(object sender, EventArgs e)
  117.         {
  118.             if (EnableVoices.Checked == true)
  119.             {
  120.                 voices_on_off = true;
  121.                 speaker.Dispose();
  122.                 speaker = new SpeechSynthesizer();
  123.                 EnableVoices.Text = "Voices Are Now Enabled";
  124.                 speaker.Rate = -2;
  125.                 speaker.Volume = 100;
  126.                 speaker.SpeakAsync("Voices are now enabled");
  127.             }
  128.             else
  129.             {
  130.  
  131.                 this.Invoke((MethodInvoker)delegate
  132.                 {
  133.                     voices_on_off = false;
  134.                     EnableVoices.Text = "Voices Are Now Disabled";
  135.                     speaker.Dispose();
  136.                     speaker = new SpeechSynthesizer();
  137.                     speaker.SpeakAsync("voices Are Now Disabled");
  138.                 });
  139.             }
  140.             setting_file.SetKey("Voices", EnableVoices.Checked.ToString());
  141.         }
  142.  
  143.  
  144.     }
  145. }
  146.  

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
  1. if (settingsmenu.voices_on_off == true)
  2.                     {
  3.                         settingsmenu.speaker.SpeakAsync("Download started");
  4.                     }
  5.                     else
  6.                     {
  7.                     }
  8.  

In the new form the line setting_file.SetKey("Voices", EnableVoices.Checked.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.GetKey("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.voices_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.
Feb 4 '11 #1
0 1334

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Laurent | last post by:
I have got a three state checkbox, where i would like to apply a readonly properties in order to keepthe three state view (Check and Blank, Unchecked and Blank, Checked and shaded) when my...
3
by: Roberto Castro | last post by:
Hello! I have been assigned for the first time an adp Access project and so far I have managed to make the changes needed for some requirements. However, I am struggling to find the place where...
0
by: Dan Neely | last post by:
Winform labels, buttons, etc don't respond to the normal/large/extra large font settings that can be specified in display properties. Is there an easy way to do an appwide detection+change at...
0
by: ABC | last post by:
How to make change one frame size (width) when I clicked a button on anothoer frame?
1
by: scolivas | last post by:
I want to make a button that will open a specific file folder that contains some crystal reports. I don't want to pick a report ...just want to "lead the user to the folder" with just a click... ...
10
by: apparker | last post by:
I'm creating a new GUI for a program and it is for a medical exam. There are so many different things to ask someone during a history it wastes too much space to make checkboxes for everything so I...
3
by: paoparaopao | last post by:
Hi, I am creating a new screen in a GUI. Can someone help me how can I make a checkbox look like it is enabled? For example, I use this code EUAMIndCheckBox.setEditable(false); and the checkbox...
26
by: Protoman | last post by:
I've written this program that simulates a 36 character, 10 rotor reciprocal rotor cipher, w/ a plugboard. Any way I can make the plugboard function more compact and/or be able to change the...
2
by: marius4674 | last post by:
I want to use a combobox to change a checkbox but the combobox take information from a table 1 and checkbox from table 2. How do I specify for the specific Combobox.Value to change the...
2
by: dangerouskicker | last post by:
dear friends any one can guide me or help, How i can change checkbox and radio button color change with java script regards devang
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.