简单实现winform图片幻灯片效果

前台添加一个转载图片的pannel、一个装载数字的pannel、timer控件就可以了。

由于我这个项目是通过webservice获取二进制流的图片格式,你如果需要用,只需要修改相应的代码就可以了

 
  
1 private int productID;
2 // private decimal price;
3 private int focusID = 0 ; // 图片展示当前iD
4 private byte [][] bytes;
5 public int ProductID
6 {
7 get { return productID; }
8 set { productID = value; }
9 }
10 private void pictureBox1_Click( object sender, EventArgs e)
11 {
12 this .Close();
13 }
14
15 private void ProductView_Load( object sender, EventArgs e)
16 {
17 SRMProduct.ProductService productService = new SRMProduct.ProductService();
18 SRMProduct.T_Product tp = new SRMProduct.T_Product();
19 tp = productService.GetProductDetails(productID);
20 if (tp != null )
21 {
22 label3.Text = tp.DisplayName;
23 label4.Text = tp.SupplyPrice.ToString();
24 bytes = tp.ImgArray;
25 ShowFlashPictures();
26 }
27 }
28
29 private void ShowFlashPictures()
30 {
31 panel1.Controls.Clear();
32 int xp = 0 ;
33 for ( int i = 0 ; i < bytes.Length; i ++ )
34 {
35 Label lbl = new Label();
36 lbl.Text = (i + 1 ).ToString();
37 lbl.Tag = i;
38 if (i != focusID)
39 {
40 lbl.BackColor = Color.Black;
41 lbl.ForeColor = Color.White;
42 }
43 else
44 {
45 lbl.BackColor = Color.Black;
46 lbl.ForeColor = Color.Red;
47 }
48
49 lbl.Width = 12 ;
50 lbl.Height = 12 ;
51 lbl.Cursor = Cursors.Hand;
52 // lbl.Click += new System.EventHandler(this.Lbl_Click);
53 lbl.MouseEnter += new System.EventHandler( this .Lbl_Click);
54 xp = xp + 20 ;
55 lbl.Location = new Point(xp, 0 );
56 panel1.Controls.Add(lbl);
57 }
58 panel2.Controls.Clear();
59 PictureBox pb = new PictureBox();
60 pb.BackgroundImage = Image.FromStream(BytesToStream(bytes[focusID]));
61 pb.Size = new System.Drawing.Size( 340 , 460 );
62 pb.BackgroundImageLayout = ImageLayout.Stretch;
63 panel2.Controls.Add(pb);
64 focusID ++ ;
65 if (focusID > 4 )
66 {
67 focusID = 0 ;
68 }
69 }
70
71 private void Lbl_Click( object sender, EventArgs e)
72 {
73
74 Label lbl = (Label)sender;
75 focusID = int .Parse(lbl.Tag.ToString());
76 // this.timer1.Enabled = false;
77 }
78
79 private Stream BytesToStream( byte [] bytes)
80 {
81 Stream stream = new MemoryStream(bytes);
82 return stream;
83 }
84
85 private void timer1_Tick( object sender, EventArgs e)
86 {
87 ShowFlashPictures();
88 }

转载于:https://www.cnblogs.com/xuwenfeng/articles/1970027.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值