Exemple #1
0
        public string RunTests(ref int failCount, ref int testCount)
        {
            int expectedResult = 20;
            eventCount = 0;
            DialogResult expectedDialogResult = DialogResult.OK;
            using (ProgressBarForm prog = new ProgressBarForm("Testing...", (int)expectedResult, true))
            {
                prog.RunWorkerCompleted += new RunWorkerCompletedEventHandler(prog_RunWorkerCompleted);
                MessageBox.Show("Will start progress bar with text box. Wait 2 seconds. Do not click Cancel");
                prog.ButtonWidth += 30;
                prog.StartWorker(Operation, expectedResult);
                if (expectedDialogResult != prog.DialogResult) Console.WriteLine("Failure: " + (++failCount)); testCount++;
                if (eventCount != 1) Console.WriteLine("Failure: " + (++failCount)); testCount++;
                if (prog.DialogResult == DialogResult.OK && expectedResult != (int)prog.Result) Console.WriteLine("Failure: " + (++failCount)); testCount++;
            }
            expectedDialogResult = DialogResult.Cancel;
            expectedResult = 50;
            using (ProgressBarForm prog = new ProgressBarForm("Testing...", (int)expectedResult, false))
            {
                prog.RunWorkerCompleted += new RunWorkerCompletedEventHandler(prog_RunWorkerCompleted);
                MessageBox.Show("Will start progress bar without text box. Click Cancel");
                prog.StartWorker(Operation, expectedResult);
                if (expectedDialogResult != prog.DialogResult) Console.WriteLine("Failure: " + (++failCount)); testCount++;
                if (eventCount != 2) Console.WriteLine("Failure: " + (++failCount)); testCount++;
                if (prog.DialogResult == DialogResult.OK && expectedResult != (int)prog.Result) Console.WriteLine("Failure: " + (++failCount)); testCount++;
            }

            return "";
        }
 /// <summary>
 /// Convert colours to fit a given colourmap
 /// </summary>
 /// <param name="cmap">The colourmap to fit.</param>
 public void ReduceColourDepth(IColourMap cmap)
 {
     ColourMap = cmap;
     this.TargetColours = 0;
     Bitmap saved = new Bitmap(mOutput);
     ProgressBarForm prog = new ProgressBarForm("Fitting Image to Colour Map...");
     prog.CanCancel = false;
     prog.StartWorker(ReduceColourDepth, this);
     Console.WriteLine("ReduceColourDepth: final number of colours = " + ColourMap.Count);
 }
 public void ReplaceColoursWithPatterns(PatternEditor patterns)
 {
     mPatterns = patterns.GetPatterns();
     Bitmap saved = new Bitmap(mOutput);
     ProgressBarForm prog = new ProgressBarForm("Replacing Colours With Patterns...");
     prog.StartWorker(ReplaceColoursWithPatterns, this);
     if (prog.DialogResult != System.Windows.Forms.DialogResult.OK)
     {
         mOutput = saved;
     }
 }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="cmap"></param>
        /// <param name="maxColours"></param>
        public void ReduceColourDepth(int maxColours)
        {
            if (ColourMap == null) return;
            this.TargetColours = maxColours;
            UpdateColourMapFromImage();
            int toRemove = ColourMap.Count - TargetColours;
            // Don't bother if we're already less than the target or have no ColourMap.
            if (toRemove <= 0) return;

            Bitmap saved = new Bitmap(mOutput);
            ProgressBarForm prog = new ProgressBarForm("Reducing Colour Depth...");
            prog.StartWorker(ReduceColourDepth, this);
            if (prog.DialogResult != System.Windows.Forms.DialogResult.OK)
            {
                mOutput = saved;
                UpdateColourMapFromImage();
            }
        }