Пример #1
0
        public Form1()
        {
            try
            {
                //InitializeComponent();
                string filePath;
                Bitmap bmp = GetImage(out filePath);
                LogEvent(filePath);

//                Cycler.WindowsAPI.SetDesktopBackground(bmp,
//                    Cycler.DesktopBackgroundStyle.Centered);

                string localPath = Path.Combine(
                    System.Environment.GetFolderPath(
                        Environment.SpecialFolder.MyPictures), "desktop.bmp");
                bmp.Save(localPath, System.Drawing.Imaging.ImageFormat.Bmp);
                Wallpaper.SetWallpaper(localPath, WallpaperStyle.Center);
            }
            catch (SecurityException se)
            {
                //イベントソースを作成できなかった場合
                MessageBox.Show("初回のみ、管理者権限で起動してください。", "WallpaperSetter");
                throw se;
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "WallpaperSetter",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error,
                                MessageBoxDefaultButton.Button1,
                                MessageBoxOptions.DefaultDesktopOnly);
            }
        }
Пример #2
0
 private void button2_Click_1(object sender, EventArgs e)
 {
     if (pictureBox1.Image != null)
     {
         string       file_name = Path.Combine(Path.GetTempPath(), "wallsetterimage.bmp");
         MemoryStream mem       = new MemoryStream();
         pictureBox1.Image.Save(mem, System.Drawing.Imaging.ImageFormat.Bmp);
         File.WriteAllBytes(file_name, mem.ToArray());
         mem.Dispose();
         Wallpaper.SetFromFile(file_name, Wallpaper.Style.Stretched);
     }
 }