load{
 PictureBox pb = new PictureBox();
System.Drawing.Bitmap bm = new System.Drawing.Bitmap(path);
                    ///获取图片缩略图开始   
                    Image.GetThumbnailImageAbort myCallback = new Image.GetThumbnailImageAbort(ThumbnailCallback);                    
                    pb.Image = img;
                    pb.Name = path;
                    
                    pb.Click += new EventHandler(pb_Click);
                    pb.Width = 200;
                    pb.Height = 150;
                    pb.BorderStyle = BorderStyle.FixedSingle;
} protected void pb_Click(object sender, EventArgs e)
        {
           Image piccy = Image.FromFile(?????????????);
            this.Imagepanel.AutoScrollMinSize = piccy.Size;
            Point[] picccyBounds = new Point[3];
            picccyBounds[0] = new Point(0, 0);
            picccyBounds[1] = new Point(Imagepanel.Width, 0);
            picccyBounds[2] = new Point(0, Imagepanel.Height);
        }在动态生成时pb我添加了click事件,但是当我点击图片时,我想把他放大。需要传个path,怎么传到事件中来.就是把pb的Name 拿到,注意是动态生成,所以pb_Click中点不出pb,因为pb是在其他方法里的。

解决方案 »

  1.   


    protected void pb_Click(object sender, EventArgs e)
            {
               Image piccy = (sender as PictureBox).Image;
                this.Imagepanel.AutoScrollMinSize = piccy.Size;
                Point[] picccyBounds = new Point[3];
                picccyBounds[0] = new Point(0, 0);
                picccyBounds[1] = new Point(Imagepanel.Width, 0);
                picccyBounds[2] = new Point(0, Imagepanel.Height);
            }
      

  2.   

    因为CLICK中的sender的是你点击的对象实例
     protected void pb_Click(object sender, EventArgs e)
            {
    PictureBox pb_Temp = sender as PictureBox;
    if ( pb_Temp != null )
    {
    //如果你是把名字存到PB的Name中了,这个sName就是你的图片名字么?
    string sName = pb_Temp.Name;
               Image piccy = Image.FromFile(?????????????);
                this.Imagepanel.AutoScrollMinSize = piccy.Size;
                Point[] picccyBounds = new Point[3];
                picccyBounds[0] = new Point(0, 0);
                picccyBounds[1] = new Point(Imagepanel.Width, 0);
                picccyBounds[2] = new Point(0, Imagepanel.Height);
    }
            }