圆形应用中背景颜色不变

时间:2010-12-01 22:07:45

标签: c# .net background-color shaped-window

我正在编写一个简单的背景颜色更改程序中的可视控件和颜色。我还想要合并圆形应用程序窗口,我通过创建一个由黑色包围的实心圆的位图并使黑色透明来完成。现在我的背景色不会循环。任何人都可以告诉我如何解决这个问题。我会包含我的代码以防万一它有所帮助,但我认为这是一个表单属性问题。谢谢你的帮助!

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;
        }
    }


}

}

1 个答案:

答案 0 :(得分:0)

每次更改组件的外观并想要显示此更改时,请调用

myComponent.Invalidate();

这会迫使对手重绘自己。既然你在那里,有很多方法可以优化重绘,但我认为上面的内容应该让你开始。