初学c#,想写一个程序 开机自动启动 每间隔10分钟在c:\pic\目录下随机挑选一张图片作为桌面壁纸
初学c#,想写一个程序 开机自动启动 每间隔10分钟在c:\pic\目录下随机挑选一张图片作为桌面壁纸
public enum ShowType { 居中, 平铺, 拉伸 } [DllImport("user32.dll", EntryPoint = "SystemParametersInfo")] public static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni); private FileInfo[] file = null; private void timer1_Tick(object sender, EventArgs e) { Random rd = new Random(); int index = rd.Next(1, file.Length); string path = file[index].DirectoryName + "\\" + file[index].Name; SystemParametersInfo(20, 1, path, 1); } private void Form1_Load(object sender, EventArgs e) { //设置墙纸显示方式 SetShowType(ShowType.拉伸); file = GetFile(); timer1.Start(); } public void SetShowType(ShowType type) { RegistryKey myRegKey = Registry.CurrentUser.OpenSubKey(@"Control Panel\desktop", true); if (type == ShowType.平铺) { myRegKey.SetValue("TileWallpaper", "1"); myRegKey.SetValue("WallpaperStyle", "0"); } else if (type == ShowType.居中) { myRegKey.SetValue("TileWallpaper", "0"); myRegKey.SetValue("WallpaperStyle", "0"); } else if (type == ShowType.拉伸) { myRegKey.SetValue("TileWallpaper", "0"); myRegKey.SetValue("WallpaperStyle", "2"); } myRegKey.Close(); } public FileInfo[] GetFile() { DirectoryInfo dirInfo = new DirectoryInfo("c:\\pic"); return dirInfo.GetFiles(); }