C# PictureBox 使用心得


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.


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM