Synchronously loading image
PictureBox pbx = new PictureBox();
pbx.Image = Image.FromFile(filename);
or
PictureBox pbx = new PictureBox();
pbx.Load(filename); // filename could be the url file://filename
Asynchronously loading image
private void btnOpen_Click(object sender, EventArgs e)
{
PictureBox pbxPic= new PictureBox();
pbxPic.WaitOnLoad = false;
pbxPic.LoadAsync(url or filename);
}
private void pbxPic_LoadCompleted(object sender, AsyncCompletedEventArgs e)
{
this.stsStatus.SuspendLayout();
this.stsStatus.Items["tsslblLocation"].Text = pbxPic.ImageLocation;
this.stsStatus.ResumeLayout(false);
this.stsStatus.PerformLayout();
}
private void pbxPic_LoadProgressChanged(object sender, ProgressChangedEventArgs e)
{
ToolStripProgressBar pgb = this.stsStatus.Items["tsspgbLoading"] as ToolStripProgressBar;
if (pgb != null)
{
pgb.Value = e.ProgressPercentage;
}
}
Show Image in picturebox
The simple one is use PictureBoxSizeMode.Zoom enum to make the image fit to the picturebox in radio
If you want to show the scroll bar, you should add picturebox into a panel. And then set panel’ autoscroll as true and set picturebox’s sizemode as PictureBoxSizeMode as Auto.