var pictureBox = new PictureBox(); pictureBox.Image = Image.FromFile(@"C:\example\image.jpg"); // Invoke a delegate on the UI thread pictureBox.Invoke(new Action(() => { pictureBox.SizeMode = PictureBoxSizeMode.StretchImage; }));
var pictureBox = new PictureBox(); pictureBox.Image = Image.FromFile(@"C:\example\image.jpg"); // Invoke a delegate with a parameter on the UI thread pictureBox.Invoke(new ActionIn this example, we create a new PictureBox and set its image to a file on disk. We then use the Invoke method to set the ImageLocation property of the PictureBox to a URL on the UI thread. The URL is passed as a parameter to the delegate using a lambda expression. The System.Windows.Forms namespace is part of the .NET Framework Class Library.((text) => { pictureBox.ImageLocation = text; }), @"http://example.com/image.jpg");