【问题标题】:background color not changing in circular application背景颜色在圆形应用程序中不变
【发布时间】:2011-05-18 19:07:13
【问题描述】:

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

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


}

}

【问题讨论】:

  • 你应该添加一个语言标签

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


【解决方案1】:

每次您更改了组件的外观并希望显示此更改时,调用

myComponent.Invalidate();

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

【讨论】:

  • 谢谢。我很感激帮助。我试试看。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-05-27
  • 1970-01-01
  • 2016-07-09
  • 2018-11-14
  • 2019-12-21
  • 2019-10-27
  • 2012-07-14
相关资源
最近更新 更多