发布时间:2020-04-01整理:阅读:
前台添加一个转载图片的pannel、一个装载数字的pannel、timer控件就可以了。
	由于我这个项目是通过webservice获取二进制流的图片格式,你如果需要用,只需要修改相应的代码就可以了
	private int productID;
	        //private decimal price;
	        private int focusID = 0;//图片展示当前iD
	        private byte[][] bytes;
	        public int ProductID
	        {
	            get { return productID; }
	            set { productID = value; }
	        }
	        private void pictureBox1_Click(object sender, EventArgs e)
	        {
	            this.Close();
	        }
	
	        private void ProductView_Load(object sender, EventArgs e)
	        {
	            SRMProduct.ProductService productService = new SRMProduct.ProductService();
	            SRMProduct.T_Product tp = new SRMProduct.T_Product();
	            tp = productService.GetProductDetails(productID);
	            if (tp != null)
	            {
	                label3.Text = tp.DisplayName;
	                label4.Text = tp.SupplyPrice.ToString();
	                bytes = tp.ImgArray;
	                ShowFlashPictures();
	            }
	        }
	
	        private void ShowFlashPictures()
	        {
	            panel1.Controls.Clear();
	            int xp = 0;
	            for (int i = 0; i < bytes.Length; i++)
	            {
	                Label lbl = new Label();
	                lbl.Text = (i+1).ToString();
	                lbl.Tag = i;
	                if (i != focusID)
	                {
	                    lbl.BackColor = Color.Black;
	                    lbl.ForeColor = Color.White;
	                }
	                else
	                {
	                    lbl.BackColor = Color.Black;
	                    lbl.ForeColor = Color.Red;
	                }
	
	                lbl.Width = 12;
	                lbl.Height = 12;
	                lbl.Cursor = Cursors.Hand;
	                //lbl.Click += new System.EventHandler(this.Lbl_Click);
	                lbl.MouseEnter += new System.EventHandler(this.Lbl_Click);
	                xp = xp + 20;
	                lbl.Location = new Point(xp, 0);
	                panel1.Controls.Add(lbl);
	            }
	            panel2.Controls.Clear();
	            PictureBox pb = new PictureBox();
	            pb.BackgroundImage = Image.FromStream(BytesToStream(bytes[focusID]));
	            pb.Size = new System.Drawing.Size(340, 460);
	            pb.BackgroundImageLayout = ImageLayout.Stretch;
	            panel2.Controls.Add(pb);
	            focusID++;
	            if (focusID > 4)
	            {
	                focusID = 0;
	            }
	        }
	
	        private void Lbl_Click(object sender, EventArgs e)
	        {
	           
	            Label lbl = (Label)sender;
	            focusID = int.Parse(lbl.Tag.ToString());
	            //this.timer1.Enabled = false;
	        }
	
	        private Stream BytesToStream(byte[] bytes)
	        {
	            Stream stream = new MemoryStream(bytes);
	            return stream;
	        }
	
	        private void timer1_Tick(object sender, EventArgs e)
	        {
	            ShowFlashPictures();
	        }
欢迎分享转载→ 简单实现winform图片幻灯片效果