圆形应用程序中的背景颜色不改变

发布于 2024-10-05 03:30:41 字数 2134 浏览 3 评论 0原文

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

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


}

}

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


}

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

注定孤独终老 2024-10-12 03:32:23

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

myComponent.Invalidate();

这会强制组件重新绘制自身。现在您已经了解了,有多种方法可以优化重绘,但我认为上述内容应该可以帮助您入门。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文