Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Dealing with Progressive Operations

, 10 May 2010 CPOL
Through a clean OOP solution to deal with progressive operations, I will implicitly show you how OOP principles can work together to make a full, clean solution.
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 Erik.Utilities;
using Erik.Utilities.Interfaces;
using Erik.Utilities.Bases;

namespace OneThreadSamples
{
    public partial class frmMain : Form
    {
        Bitmap _bmp;

        public frmMain()
        {
            InitializeComponent();
        }

        private void mnuEffects_DropDownOpening(object sender, EventArgs e)
        {
            bool enable = pct.Image != null;

            foreach (ToolStripItem itm in mnuEffects.DropDownItems)
                itm.Enabled = enable;
        }

        private void mnuFileExit_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void mnuFileOpen_Click(object sender, EventArgs e)
        {
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    _bmp = Bitmap.FromFile(dlg.FileName) as Bitmap;
                    pct.Image = _bmp;
                }
                catch
                {
                    MessageBox.Show(this, "The file is not a valid Bitmap",
                        "Problem", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }

        private void mnuEffectsNegative_Click(object sender, EventArgs e)
        {
            Lib.StartProgressiveOperation(new NegativePO(_bmp), this);
            pct.Refresh();
        }

        private void mnuEffectsGray_Click(object sender, EventArgs e)
        {
            Lib.StartProgressiveOperation(new GrayScalePO(_bmp), this);
            pct.Refresh();
        }

        private void mnuEffectsAllEffects_Click(object sender, EventArgs e)
        {
            List<IProgressiveOperation> opList = new List<IProgressiveOperation>();
            opList.Add(new NegativePO(_bmp));
            opList.Add(new GrayScalePO(_bmp));

            Lib.StartProgressiveOperation(new CompositePO(opList), this);
            pct.Refresh();
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

_Erik_
Technical Lead
Spain Spain
No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.1411023.1 | Last Updated 10 May 2010
Article Copyright 2010 by _Erik_
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid