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