public BitmapPreparationForm(TemplateForm templateForm)
        {
            InitializeComponent();

            FormClosing += delegate(object sender, FormClosingEventArgs e)
            {
                e.Cancel     = true;
                this.Visible = false;
            };

            this.Icon = Win.AssemblyRoutines.GetAppIcon();

            //defaultBitmapPreprocessorClassDefinitions.Items =

            this.templateForm = templateForm;

            Template template = null;

            Activated += delegate
            {
                template = templateForm.GetTemplateFromUI(false);
                SetUI(template, true);
            };

            TesseractPageSegMode.Items.AddRange(new object[] {
                Tesseract.PageSegMode.Auto,
                Tesseract.PageSegMode.AutoOnly,
                Tesseract.PageSegMode.AutoOsd,
                Tesseract.PageSegMode.CircleWord,
                Tesseract.PageSegMode.Count,
                Tesseract.PageSegMode.OsdOnly,
                Tesseract.PageSegMode.RawLine,
                Tesseract.PageSegMode.SingleBlock,
                Tesseract.PageSegMode.SingleBlockVertText,
                Tesseract.PageSegMode.SingleChar,
                Tesseract.PageSegMode.SingleColumn,
                Tesseract.PageSegMode.SingleLine,
                Tesseract.PageSegMode.SingleWord,
                Tesseract.PageSegMode.SparseText,
                Tesseract.PageSegMode.SparseTextOsd
            });

            PageRotation.SelectedIndexChanged             += delegate { changed = true; };
            Deskew.CheckedChanged                         += delegate { changed = true; };
            DeskewBlockMaxHeight.ValueChanged             += delegate { changed = true; };
            DeskewBlockMinSpan.ValueChanged               += delegate { changed = true; };
            ScalingAnchor.SelectedIndexChanged            += delegate { changed = true; };
            CvImageScalePyramidStep.ValueChanged          += delegate { changed = true; };
            bitmapPreprocessorClassDefinition.TextChanged += delegate { changed = true; };
            TesseractPageSegMode.SelectedIndexChanged     += delegate { changed = true; };
            PreprocessBitmap.CheckedChanged               += delegate
            {
                bitmapPreprocessorClassDefinition.Enabled = PreprocessBitmap.Checked;
                if (bitmapPreprocessorClassDefinition.Enabled && string.IsNullOrWhiteSpace(bitmapPreprocessorClassDefinition.Text))
                {
                    string className = Regex.Replace(template.Name, @"[\W]", "_");
                    bitmapPreprocessorClassDefinition.Text = Regex.Replace(defaultBitmapPreprocessor, @"Default_BitmapPreprocessor", className + "_BitmapPreprocessor", RegexOptions.Singleline);
                }
            };
        }
        public ScanTemplateForm(TemplateForm templateForm)
        {
            InitializeComponent();

            FormClosing += delegate(object sender, FormClosingEventArgs e)
            {
                e.Cancel     = true;
                this.Visible = false;
            };

            Icon = Win.AssemblyRoutines.GetAppIcon();

            this.templateForm = templateForm;

            Template template = null;

            Activated += delegate
            {
                template = templateForm.GetTemplateFromUI(false);
                SetUI(template, true);
            };

            PageRotation.SelectedIndexChanged  += delegate { changed = true; };
            ScalingAnchor.SelectedIndexChanged += delegate { changed = true; };
            bitmapPreprocessorClassDefinition.SetHighlighting("C#");
            bitmapPreprocessorClassDefinition.TextChanged += delegate { changed = true; };
            bitmapPreprocessorClassDefinition.Enter       += delegate
            {
                if (string.IsNullOrWhiteSpace(bitmapPreprocessorClassDefinition.Text))
                {
                    string className = Regex.Replace(template.Name, @"[\W]", "_");
                    bitmapPreprocessorClassDefinition.Text = Regex.Replace(defaultBitmapPreprocessor, @"Default_BitmapPreprocessor", className + "_BitmapPreprocessor", RegexOptions.Singleline);
                }
            };
            Deskew.CheckedChanged += delegate
            {
                changed = true;
                DeskewMarginColor.Enabled     = DeskewSingleBlock.Enabled = DeskewColumnOfBlocks.Enabled = DeskewStructuringElementX.Enabled = DeskewStructuringElementY.Enabled = Deskew.Checked;
                DeskewContourMaxCount.Enabled = DeskewAngleMaxDeviation.Enabled = DeskewBlockMaxHeight.Enabled = DeskewBlockMinGap.Enabled = DeskewColumnOfBlocks.Checked;
            };
            DeskewSingleBlock.CheckedChanged    += delegate { changed = true; };
            DeskewColumnOfBlocks.CheckedChanged += delegate
            {
                changed = true;
                DeskewBlockMaxHeight.Enabled = DeskewBlockMinGap.Enabled = DeskewColumnOfBlocks.Checked;
            };
            DeskewBlockMaxHeight.ValueChanged    += delegate { changed = true; };
            DeskewBlockMinGap.ValueChanged       += delegate { changed = true; };
            DeskewContourMaxCount.ValueChanged   += delegate { changed = true; };
            DeskewAngleMaxDeviation.ValueChanged += delegate { changed = true; };
            DeskewMarginColor.BackColorChanged   += delegate { changed = true; };
        }