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

Visual Studio Add-in for testing regular expressions

, 1 Dec 2010 CPOL
An add-in for debugging and creating regular expression directly in Visual Studio
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace RegexTester.UserControls
{
    /// <summary>
    /// Control wrapping other control to allow it to show validity.
    /// A border is put around the wrapped control, showing green if valid
    /// and red otherwise.
    /// </summary>
    public partial class ShowValidDecorator : UserControl
    {
        private Color ColorValid = Color.Green;
        private Color ColorInvalid = Color.Red;
        private bool isValid = true;
        private int borderWidth = 1;
        private Control wrappedControl;

        public ShowValidDecorator()
        {
            this.SizeChanged += WrappedControlResized;
        }

        public ShowValidDecorator(UserControl wrappedControl)
            : base()
        {
            this.WrappedControl = wrappedControl;
            this.SizeChanged += WrappedControlResized;
            SetProperties();
        }

        private void SetProperties()
        {
            if (WrappedControl != null)
            {
                WrappedControl.Location = new Point(borderWidth, borderWidth);
                WrappedControl.Height = Height - 2 * borderWidth;
                WrappedControl.Width = Width - 2 * borderWidth;
            }
        }

        private void WrappedControlResized(object sender, EventArgs e)
        {
            SetProperties();
            Invalidate();
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            Graphics g = e.Graphics;
            Color color = IsValid ? ColorValid : ColorInvalid;
            Brush brush = new SolidBrush(color);
            g.FillRectangle(brush, 0, 0, this.Width, borderWidth);
            g.FillRectangle(brush, 0, 0, borderWidth, this.Height);
            g.FillRectangle(brush, 0, this.Height - borderWidth, this.Width, borderWidth);
            g.FillRectangle(brush, this.Width - borderWidth, 0, borderWidth, this.Height);
        }

        public bool IsValid
        {
            get { return isValid; }
            set { isValid = value; Invalidate(); }
        }

        public int BorderWidth
        {
            get { return borderWidth; }
            set { borderWidth = value; SetProperties(); }
        }

        public Control WrappedControl
        {
            get { return wrappedControl; }
            set
            {
                wrappedControl = value;
                this.Controls.Clear();
                this.Controls.Add(wrappedControl);
                SetProperties();
            }
        }
    }
}

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

Andreas Andersen
Software Developer (Senior)
Denmark Denmark
.NET developer. I wanted to be first an astronaut, then a jet pilot, but when I got a Commodore 64 for Christmas I never looked back. Also I would never have qualified for the first two things and everybody knows computer programmers get all the girls.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.141223.1 | Last Updated 1 Dec 2010
Article Copyright 2010 by Andreas Andersen
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid