C#Windows Forms (Demo.SYS)--xdd
1 private void Show_background_picture()//随机更换背景 2 { 3 string img_no = "01";//默认值 4 Random ran = new Random(); 5 int bg_index = ran.Next(1, 3);//返回一个1到3之间的随机数(1,2,3) 6 if (bg_index < 10)//防止背景图片大于9张,图片文件名为01 02 03... 7 img_no = "0" + bg_index.ToString(); 8 else 9 img_no = bg_index.ToString(); 10 //if 没有end 11 //设置背景图片 @"\picture\"等效于"\\picture\\" 12 this.BackgroundImage = Image.FromFile(Application.StartupPath + @"\picture\" + img_no + ".png");//参数:存储图片文件的路径 13 }
write bu xdd 2019-08-22 00:21:20
本文来自博客园,作者:xdd1997
转载请注明:https://www.cnblogs.com/xdd1997/p/11392081.html
![]()