protected ProgressSubject subject;                   // All observers will have a subject

        public BaseProgressObserver(ProgressSubject subject) // Subject is handed in via constructor
        {
            this.subject = subject;                          // Assign passed in subject to class member

            // We can just use generic EventHandler because we don't need to pass any data
            EventHandler handler = new EventHandler(ProgressHandlerMethod);

            subject.ProgressEvent += handler;
        }
Beispiel #2
0
        public Form1()
        {
            InitializeComponent();

            // Create instance of subject first so that observers can subscribe
            subject = new ProgressSubject();
            // Instantiate our observers once subject exists
            progressBarObserver = new ProgressBarObserver(subject, progressBar1);
            trackBarObserver = new TrackBarObserver(subject, trackBar1);
            upDownObserver = new UpDownObserver(subject, numericUpDown1, this);
        }
Beispiel #3
0
        public Form1()
        {
            InitializeComponent();

            // Create instance of subject first so that observers can subscribe
            subject = new ProgressSubject();
            // Instantiate our observers once subject exists
            progressBarObserver = new ProgressBarObserver(subject, progressBar1);
            trackBarObserver    = new TrackBarObserver(subject, trackBar1);
            upDownObserver      = new UpDownObserver(subject, numericUpDown1, this);
        }
 // Almost exactly the same as ProgressBarObserver except with a track bar instead
 public TrackBarObserver(ProgressSubject subject, TrackBar trackBar)
     : base(subject)
 {
     this.trackBar = trackBar;
 }
 // Send subject to base class, then assign the passed in progress bar to our class member progress bar
 public ProgressBarObserver(ProgressSubject subject, ProgressBar progressBar)
     : base(subject)
 {
     this.progressBar = progressBar;
 }
 // Almost exactly the same as ProgressBarObserver except with a track bar instead
 public TrackBarObserver(ProgressSubject subject, TrackBar trackBar) : base(subject)
 {
     this.trackBar = trackBar;
 }
 public UpDownObserver(ProgressSubject subject, NumericUpDown numericUpDown, Form form)
     : base(subject)
 {
     this.numericUpDown = numericUpDown;
     this.form = form;
 }
 public UpDownObserver(ProgressSubject subject, NumericUpDown numericUpDown, Form form)
     : base(subject)
 {
     this.numericUpDown = numericUpDown;
     this.form          = form;
 }
Beispiel #9
0
 // Send subject to base class, then assign the passed in progress bar to our class member progress bar
 public ProgressBarObserver(ProgressSubject subject, ProgressBar progressBar) : base(subject)
 {
     this.progressBar = progressBar;
 }