Esempio n. 1
0
 /// <summary>自动调整图片控件大小</summary>
 /// <param name="pic">图片控件</param>
 /// <param name="pan">图片空间容器</param>
 public static void AutoPictureBoxSize(PictureBox pic, Panel pan)
 {
     if (pic.Image != null)
     {
         try
         {
             System.Drawing.Image imfile = pic.Image;
             int imsw = pan.Width - 1;
             int imsh = pan.Height - 1;
             int plx  = pan.Width / 2;
             int ply  = pan.Height / 2;
             Often.AutoSizeNarrow(ref imsw, ref imsh, imfile.Size.Width, imfile.Size.Height);
             pic.Width  = imsw;
             pic.Height = imsh;
             pic.Top    = ply - (pic.Height / 2);
             pic.Left   = plx - (pic.Width / 2);
         }
         catch
         {
         }
     }
 }