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;
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 4
0
 // 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;
 }
Exemplo n.º 6
0
 // Almost exactly the same as ProgressBarObserver except with a track bar instead
 public TrackBarObserver(ProgressSubject subject, TrackBar trackBar) : base(subject)
 {
     this.trackBar = trackBar;
 }
Exemplo n.º 7
0
 public UpDownObserver(ProgressSubject subject, NumericUpDown numericUpDown, Form form)
     : base(subject)
 {
     this.numericUpDown = numericUpDown;
     this.form = form;
 }
Exemplo n.º 8
0
 public UpDownObserver(ProgressSubject subject, NumericUpDown numericUpDown, Form form)
     : base(subject)
 {
     this.numericUpDown = numericUpDown;
     this.form          = form;
 }
Exemplo n.º 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;
 }