/// <summary> /// バックグラウンドワーカー /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { // 全ディスプレイの左上の座標を取得する int minLeft = 0; int minTop = 0; foreach (Screen screen in Screen.AllScreens) { if (minLeft > screen.Bounds.Left) { minLeft = screen.Bounds.Left; } if (minTop > screen.Bounds.Top) { minTop = screen.Bounds.Top; } } // ディスプレイのインデックス int displayIndex = 0; foreach (Screen screen in Screen.AllScreens) { // ディスプレイのスクリーンショットを取得 Bitmap bmp = new Bitmap(screen.Bounds.Width, screen.Bounds.Height); using (Graphics graphics = Graphics.FromImage(bmp)) { graphics.CopyFromScreen(new Point(screen.Bounds.Left, screen.Bounds.Top), new Point(0, 0), bmp.Size); } // ピクチャーボックス作成 PictureBox pictureBox = new PictureBox(); pictureBox.Image = bmp; pictureBox.SizeMode = PictureBoxSizeMode.Zoom; // 1/16サイズで表示 pictureBox.Size = new Size(screen.Bounds.Width / 16, screen.Bounds.Height / 16); this.backgroundWorker1.ReportProgress(1, pictureBox); // 場所を移動 pictureBox.Location = new Point(minLeft / 16 * -1 + screen.Bounds.Left / 16, minTop / 16 * -1 + screen.Bounds.Top / 16); WallPaperControll wallPaperControll = new WallPaperControll(this.openFileDialog1, pictureBox, screen); this.backgroundWorker1.ReportProgress(2, wallPaperControll); wallPaperControll.Location = new Point(0, wallPaperControll.Height * displayIndex); displayIndex++; } }
private void backgroundWorker2_DoWork(object sender, DoWorkEventArgs e) { try { List <ScreenModel> screenModelList = new List <ScreenModel>(); foreach (Control conrtol in this.panel1.Controls) { WallPaperControll wallPaperControll = (WallPaperControll)conrtol; ScreenModel screenModel = new ScreenModel(); screenModel.Screen = wallPaperControll.Screen; screenModel.bitmap = new Bitmap(wallPaperControll.FilePath); screenModelList.Add(screenModel); } SetWallPaper setWallPAper = new SetWallPaper(); setWallPAper.process(screenModelList, (string)e.Argument); } catch (Exception exception) { this.backgroundWorker2.ReportProgress(0, exception); } }