c# winform 窗体 form 背景自动变换

 要操作步骤如下:

1:首先添加图片源

c# winform 窗体 form 背景自动变换_第1张图片

 

2:往窗体添加定时器timer1

在 timer1事件写上如下代码:

private void timer1_Tick(object sender, EventArgs e) { string num = null; for (int i = 1; i < 3; i++) { num += i.ToString() + ","; } num = num.Substring(0, num.Length - 1); string strSep = ","; string[] aryChar = num.Split(strSep.ToCharArray(), num.Length); Random Rnd = new Random(unchecked((int)DateTime.Now.Ticks)); int hx = Convert.ToInt32(aryChar[Rnd.Next(aryChar.Length)]); Resources rs = new Resources(); object obj = ResourceManager.GetObject(hx.ToString(), resourceCulture); this.BackgroundImage = ((System.Drawing.Bitmap)(obj)); }

 

用到属性和方法如下:

private static global::System.Globalization.CultureInfo resourceCulture; private static global::System.Resources.ResourceManager resourceMan; internal static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("loveyou.Properties.Resources", typeof(Resources).Assembly); resourceMan = temp; } return resourceMan; } }

 

到此已经结束!

你可能感兴趣的:(c# winform 窗体 form 背景自动变换)