I'm trying to incorporate my custom control called "windmill" into my application extension. I've created a few properties that I want to be visible in the properties window and when I built my project and tried to use it in a test project it did not work. To top it off, the main functionality of the control isn't working either. The basic idea is to create four rectangular objects (using the visual basic power packs rectangle control) and at run-time, change one rectangle's color after the other in sequential clockwise order on a timer tick event. However it's not working, yet when I click the custom control during debugging the color becomes brighter but never moves. Below is my source code for the custom control.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Composition;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.Design;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Dev9
{
    public partial class Windmill : UserControl
    {
        public Windmill()
        {
            InitializeComponent();
            timer1.Start();
        }

        public override Color ForeColor
        {
            get
            {
                return UpperLeft.FillGradientColor;
            }

            set
            {
                // I feel that this is the problem with both color sets.
                UpperLeft.FillGradientColor = value;
                UpperRight.FillGradientColor = value;
                LowerLeft.FillGradientColor = value;
                LowerRight.FillGradientColor = value;
            }
        }

        public override Color BackColor
        {
            get
            {
                return UpperLeft.FillColor;
            }
            set
            {
                UpperLeft.FillColor = value;
                UpperRight.FillColor = value;
                LowerLeft.FillColor = value;
                LowerRight.FillColor = value;
            }
        }

        [Browsable(true)]
        public Color RotationForeColor = Color.White;

        [Browsable(true)]
        public Color RotationBackColor = Color.Gray;

        [Browsable(true)]
        public int Speed = 100;

        private void Rotate(object sender, EventArgs e)
        {
            timer1.Interval = Speed;

            if (UpperLeft.FillColor == RotationBackColor)
            {
                UpperLeft.FillColor = BackColor;
                UpperLeft.FillGradientColor = ForeColor;
                UpperRight.FillColor = RotationBackColor;
                UpperRight.FillGradientColor = RotationForeColor;
            }

            else if (UpperRight.FillColor == RotationBackColor)
            {
                UpperRight.FillColor = BackColor;
                UpperRight.FillGradientColor = ForeColor;
                LowerRight.FillColor = RotationBackColor;
                LowerRight.FillGradientColor = RotationForeColor;
            }

            else if (LowerRight.FillColor == RotationBackColor)
            {
                LowerRight.FillColor = BackColor;
                LowerRight.FillGradientColor = ForeColor;
                LowerLeft.FillColor = RotationBackColor;
                LowerLeft.FillGradientColor = RotationForeColor;
            }

            else if (LowerLeft.FillColor == RotationBackColor)
            {
                LowerLeft.FillColor = BackColor;
                LowerLeft.FillGradientColor = ForeColor;
                UpperLeft.FillColor = RotationBackColor;
                UpperLeft.FillGradientColor = RotationForeColor;
            }
        }
    }
}

Okay so I got it to change the second square's color like I wanted, but it's not resetting the other one to the back color which means I need to spend a little more time thinking. Here's the result that progressed me further.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Composition;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.Design;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Dev9
{
    public partial class Windmill : UserControl
    {
        public Windmill()
        {
            InitializeComponent();
        }

        public enum LitSquare
        {
            UpperLeft,
            UpperRight,
            LowerRight,
            LowerLeft
        }

        [Browsable(true)]
        public override Color ForeColor
        {
            get
            {
                return UpperLeft.FillGradientColor;
            }

            set
            {
                if (CurrentlyLitSquare == LitSquare.UpperLeft)
                {
                    UpperRight.FillGradientColor = value;
                    LowerLeft.FillGradientColor = value;
                    LowerRight.FillGradientColor = value;
                }

                else if (CurrentlyLitSquare == LitSquare.UpperRight)
                {
                    UpperLeft.FillGradientColor = value;
                    LowerLeft.FillGradientColor = value;
                    LowerRight.FillGradientColor = value;
                }

                else if (CurrentlyLitSquare == LitSquare.LowerRight)
                {
                    UpperLeft.FillGradientColor = value;
                    UpperRight.FillGradientColor = value;
                    LowerLeft.FillGradientColor = value;
                }

                else if (CurrentlyLitSquare == LitSquare.LowerLeft)
                {
                    UpperLeft.FillGradientColor = value;
                    UpperRight.FillGradientColor = value;
                    LowerRight.FillGradientColor = value;
                }
            }
        }

        [Browsable(true)]
        public override Color BackColor
        {
            get
            {
                return UpperLeft.FillColor;
            }

            set
            {
                if (CurrentlyLitSquare == LitSquare.UpperLeft)
                {
                    UpperRight.FillColor = value;
                    LowerLeft.FillColor = value;
                    LowerRight.FillColor = value;
                }

                else if (CurrentlyLitSquare == LitSquare.UpperRight)
                {
                    UpperLeft.FillColor = value;
                    LowerLeft.FillColor = value;
                    LowerRight.FillColor = value;
                }

                else if (CurrentlyLitSquare == LitSquare.LowerRight)
                {
                    UpperLeft.FillColor = value;
                    UpperRight.FillColor = value;
                    LowerLeft.FillColor = value;
                }

                else if (CurrentlyLitSquare == LitSquare.LowerLeft)
                {
                    UpperLeft.FillColor = value;
                    UpperRight.FillColor = value;
                    LowerRight.FillColor = value;
                }
            }
        }

        [Browsable(true)]
        public Color RotationForeColor = Color.White;

        [Browsable(true)]
        public Color RotationBackColor = Color.Gray;

        [Browsable(true)]
        public int Speed = 100;

        [Browsable(true)]
        public LitSquare CurrentlyLitSquare = LitSquare.UpperLeft;

        public void Start()
        {
            timer1.Interval = Speed;
            timer1.Start();
        }

        public void Stop()
        {
            timer1.Stop();
        }

        private void Rotate(object sender, EventArgs e)
        {
            if (UpperLeft.FillColor == RotationBackColor)
            {
                UpperLeft.FillColor = BackColor;
                UpperLeft.FillGradientColor = ForeColor;
                UpperRight.FillColor = RotationBackColor;
                UpperRight.FillGradientColor = RotationForeColor;
            }

            else if (UpperRight.FillColor == RotationBackColor)
            {
                UpperRight.FillColor = BackColor;
                UpperRight.FillGradientColor = ForeColor;
                LowerRight.FillColor = RotationBackColor;
                LowerRight.FillGradientColor = RotationForeColor;
            }

            else if (LowerRight.FillColor == RotationBackColor)
            {
                LowerRight.FillColor = BackColor;
                LowerRight.FillGradientColor = ForeColor;
                LowerLeft.FillColor = RotationBackColor;
                LowerLeft.FillGradientColor = RotationForeColor;
            }

            else if (LowerLeft.FillColor == RotationBackColor)
            {
                LowerLeft.FillColor = BackColor;
                LowerLeft.FillGradientColor = ForeColor;
                UpperLeft.FillColor = RotationBackColor;
                UpperLeft.FillGradientColor = RotationForeColor;
            }
        }
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.