c#实现改变背景颜色、背景图片、插入背景音乐

来源:互联网 发布:mysql 时间小于等于 编辑:程序博客网 时间:2024/04/19 22:36

<span style="background-color: rgb(255, 255, 255); font-family: Arial, Helvetica, sans-serif;">今天的作业苦恼了好久,特别是不知道怎么找接口,后来看了一个例子豁然开朗,试了一下自己改了下背景颜色,居然成功了!get新技能!</span>


【demo】c#改变背景颜色、背景图片、插入背景音乐

(为了简便表示都用button触发了)


背景音乐在窗口初始化的时候加进去(网上的说法是最好在bin里面添加,还有注意是“/”啊,和本地路径相反的斜杠啊)

   public library()        {            InitializeComponent();            SoundPlayer sp = new SoundPlayer("D:/c#/demo/demo/bin/aa.wav");//必须是带.wav扩展名的音频文件            sp.PlayLooping();//循环播放        }

背景图片插入

       private void button1_Click(object sender, EventArgs e)        {             string[] sMystring;             OpenFileDialog ofdMyofd = new OpenFileDialog();             ofdMyofd.FileName = "Please Select Picture";             ofdMyofd.Filter = "*.jpg|*.*";             if (ofdMyofd.ShowDialog() == DialogResult.OK)             {                 sMystring=ofdMyofd.FileNames;                 this.BackgroundImage = Image.FromFile(sMystring[0]);             }          }


背景颜色插入

        private void button2_Click(object sender, EventArgs e)        {            if (colorDialog1.ShowDialog() == DialogResult.OK)            {                Color color = colorDialog1.Color;                this.BackColor = color;            }        }



0 0
原创粉丝点击