public static void UpdatePictureBox(Bitmap bmap) { if (pixelBoxEffectref.InvokeRequired) { UpdatePictureBoxCallback d = new UpdatePictureBoxCallback(UpdatePictureBox); Parent.Invoke(d, new object[] { bmap }); } else { pixelBoxEffectref.Image = bmap; } }
public static int[] UpdatePictureBox(System.Windows.Forms.PictureBox PictureBoxControl, Image Image2Show, bool NormalizeImage = false) { int[] retval = new int[2]; retval[0] = 0; retval[1] = 0; int[] nullretval = new int[2]; retval[0] = 0; retval[1] = 0; if (PictureBoxControl.InvokeRequired) { UpdatePictureBoxCallback d = UpdatePictureBox; PictureBoxControl.Invoke(d, new object[] { PictureBoxControl, Image2Show, NormalizeImage }); } else { if (Image2Show == null) { PictureBoxControl.Image = null; return(nullretval); } if (NormalizeImage) { int th_width = PictureBoxControl.Width; int th_height = (int)(Math.Round(((double)th_width / (double)Image2Show.Width) * (double)Image2Show.Height, 0)); if (th_height > PictureBoxControl.Height) { th_height = PictureBoxControl.Height; th_width = (int)Math.Round((double)th_height * (double)Image2Show.Width / (double)Image2Show.Height); } PictureBoxControl.Image = Image2Show.GetThumbnailImage(th_width, th_height, null, IntPtr.Zero); retval[0] = th_width; retval[1] = th_height; } else { PictureBoxControl.Image = Image2Show; retval[0] = Image2Show.Width; retval[1] = Image2Show.Height; } } return(retval); }
// Method to update a device status picture box, ensure cross-thread support, as Spokes events come in on a different thread private void UpdateDevicePictureBox(PictureBox statePictureBox, Bitmap bitmap) { if (statePictureBox.InvokeRequired) { UpdatePictureBoxCallback d = new UpdatePictureBoxCallback(UpdateDevicePictureBox); this.Invoke(d, new object[] { statePictureBox, bitmap }); } else { statePictureBox.Image = bitmap; } }
/// <summary> /// Updates thread-safely the chart /// </summary> /// <param name="index">Index of the picturebox to update</param> /// <param name="bmp">Bitmap to display</param> void UpdatePictureBox(int index, Bitmap bmp) { if (this.PictureBoxes[index].InvokeRequired) { if (PictureBoxes[index].Parent != null) { UpdatePictureBoxCallback d = new UpdatePictureBoxCallback(UpdatePictureBox); if (PictureBoxes[index].Parent.Disposing == false) { PictureBoxes[index].Parent.Invoke(d, new object[] { index, bmp }); } } } else { try { graphics[index].DrawImage(bmp, PictureBoxes[index].DisplayRectangle); } catch (ExternalException extExc) { // Ignore this error for a start... } } }