Search code examples
c#.netbackground-colorshaped-window

background color not changing in circular application


I'm playing around with visual controls and colors in a simple background color changing program I've written. I also wanted to incorporate the circular application window, which I did by creating a bitmap of a solid circle surrounded by black and making the black transparent. Now my back ground color doesn't loop. Can anyone tell me how to fix this. Ill include my code just in case it helps but I think this is a form properties problem. Thanks for any help!

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();      
    }

    public Point mouse_offset;
    public int c;

    private void button1_Click(object sender, EventArgs e)
    {
        using (SpeechSynthesizer synth = new System.Speech.Synthesis.SpeechSynthesizer())
        {
            synth.Speak("This is a test of the emergency see sharp broadcasting network!");
            synth.Speak("The man to the left is actually trying to dance without graphics capabilities");

        }
        while (Visible)
        {
            using (SpeechSynthesizer synth = new System.Speech.Synthesis.SpeechSynthesizer())
            {
                synth.Speak("Flash dance commencing in three. two. one.");
            }
            while (Visible)
            {
                for (int c = 0; c < 255 && Visible; c++)
                {
                    this.BackColor = Color.FromArgb(c, 255 - c, c);
                    Application.DoEvents();
                    //slow();

                }


                for (int c = 255; c > 0 && Visible; c--)
                {
                    this.BackColor = Color.FromArgb(c, 255 - c, c);
                    Application.DoEvents();
                    //slow();

                }

            }
        }
    }

    public static void slow()
    {
        System.Threading.Thread.Sleep(3);
    }

    private void button2_Click(object sender, EventArgs e)
    {
        this.Close();
    }

    private void Form1_MouseDown(object sender, MouseEventArgs e)
    {
        mouse_offset = new Point(-e.X, -e.Y);

    }

    private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Left) 
        {
            Point mousePos = Control.MousePosition;
             mousePos.Offset(mouse_offset.X, mouse_offset.Y);
            Location = mousePos;
        }
    }


}

}


Solution

  • Every time you have changed the looks of a component and want to display this change, call

    myComponent.Invalidate();
    

    This forces the conponent to redraw itself. Now that you're there, there are a number of ways to optimize redraws, but I think the above should get you started.