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


 


转载仅为学习,不会商用。
欢迎转载原创,附文链接。
原文地址:https://www.cnblogs.com/xdd1997/p/11392081.html