Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Alerting a main application form that a user setting has been changed

Posted on 2005-02-25
3
Medium Priority
?
196 Views
Last Modified: 2010-04-16
Hi experts,
  I am writing an application using MS Visual C# Express Beta, that has a modeless configuration form so that the user can change various application settings.  These settings modify the state of the values contained in 'Properties.Settings1.Value.xxx'.
  Is there any way to alert the main form to any changes that have been made to the user settings so that it can change its behaviour of say the com port used for the serialPort class?
  By the way I would describe myself as a relative beginner to C#.Net

Cheers
0
Comment
Question by:Millamba
1 Comment
 
LVL 1

Accepted Solution

by:
gioni_go earned 600 total points
ID: 13411894
using System;
/*Ok for this u have to use events . If u dont know what they are
 * I'll try to eplain to u a little bit .First of all there
 * are three componets in programming event driven apps.
 *First ---is  of them is YourEventArgs (the arguments passed by
 *your event)
 *Second---is the event handler (wich is a delegate)
 *Third --- is the actual event
 *OK let's start
 *
*/
namespace Proj
{
      //////////////////////////////////////////////////////////////////
      public class CustomEventArgs:EventArgs //always must derive from
      {                                                            //this base class
            public CustomEventArgs(string type_OfChange,string value_ofch)
            {//the class constructor
                  this.type_change = type_OfChange;
                  this.value_change= value_ofch;
            }
            public readonly string type_change,value_change;
            //they must be readonly so that they can only be read
      }
      //////////////////////////////////////////////////////////////////
      
      //////////////////////////////////////////////////////////////////
      public delegate void CustomEventHandler(CustomEventArgs args);
      //we defined our delegate = pointer to a function (in c++)
      //////////////////////////////////////////////////////////////////
      
      public class Test//:Form
      {
            //let's say this is the Form class u're gonna use
            //u're gonna define a custom event like this
            public event CustomEventHandler EventYouWaitFor;
            public Test()
            {
                  
            }
            public void TheGuyCheckedTheBox()
            {
                  OnCustomEvent(new CustomEventArgs("BlackCheckBox","Checked"));
            }
            //Now we're gonna make the function that fires the event
            protected void OnCustomEvent(CustomEventArgs args)
            {
                  if(EventYouWaitFor != null)
                  {
                        EventYouWaitFor(args);
                  }
            }
      }

      public class Tester
      {
            public static void Main(String[] args)
            {
            //ok now we test app
                  Test tst = new Test();
                  tst.EventYouWaitFor += new CustomEventHandler(doOnEvent);

                  //Now when the guy presses the checkbox u get the values
                  // I already put them for u in the function
                  tst.TheGuyCheckedTheBox();
            //and voila the result
                  // U really must read a little bit about delegates and events
                  // they are scary but they are easy to understand

                  Console.ReadLine();
            }

            public static void doOnEvent(CustomEventArgs args)
            {
            Console.WriteLine(args.type_change);
                  Console.WriteLine(args.value_change);
            }
      }
}
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question