我加了Panel,怎么让他有走马灯的效果。

解决方案 »

  1.   

    同求  我是做的Gif图片加载上去的,不知道用picturebox能不能实现   
      

  2.   

    我觉得可以使用两个pictureBox,然后用定时器移动
      

  3.   


    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.IO;
    using System.Collections.Specialized;namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            PictureBox PB = new PictureBox();
            int Pos = 0;
            int CurrentBmpIndex = 0;
            Bitmap[] Bmps = new Bitmap[10];
            public Form1()
            {
                InitializeComponent(); 
            }
            void T_Tick(object sender, EventArgs e)
            {
                if (++Pos > 100)
                {
                   // CurrentBmpIndex = (CurrentBmpIndex + 1) % 3;
                    CurrentBmpIndex++;
                    Pos = 0;
                }
                Bitmap Temp = new Bitmap(100, 100);
                using (Graphics G = Graphics.FromImage(Temp))
                {
                    G.DrawImage(PB.Image, new Rectangle(-1, 0, 100, 100));
                    if (CurrentBmpIndex < 10)
                    {
                        G.DrawImage(Bmps[CurrentBmpIndex], new Rectangle(99, 0, 100, 100));
                    }
                    if (CurrentBmpIndex == 10)
                    {
                        CurrentBmpIndex = 0;
                    }
                }
                PB.Image = Temp;
            }        private void button1_Click(object sender, EventArgs e)
            {
                string path = "image";
                int i = 0;
                DirectoryInfo dinfo = new DirectoryInfo(path);
                FileInfo[] finfo = dinfo.GetFiles();
                StringCollection coll = new StringCollection();
                foreach (FileInfo file in finfo)
                {
                    Image image = Image.FromFile("image\\" + file.Name);
                    Bmps[i] = new Bitmap(100, 100);
                    using (Graphics G = Graphics.FromImage(Bmps[i]))
                        G.DrawImage(image, -1, 0, 100, 100);
                    i++;
                }
                //Bmps[0] = new Bitmap(100, 100);
                //using (Graphics G = Graphics.FromImage(Bmps[0]))
                //    G.DrawImage(PB.Properties.Resources._1,-1,0,100,100);
                //Bmps[1] = new Bitmap(100, 100);
                //using (Graphics G = Graphics.FromImage(Bmps[1]))
                //    G.Clear(Color.Green);
                //Bmps[2] = new Bitmap(100, 100);
                //using (Graphics G = Graphics.FromImage(Bmps[2]))
                //    G.Clear(Color.Blue);
                //Bmps[3] = new Bitmap(100, 100);
                //using (Graphics G = Graphics.FromImage(Bmps[3]))
                //    G.Clear(Color.Red);
                PB.Parent = this;
                PB.Size = new Size(100, 100);
                PB.Image = Bmps[0];
                CurrentBmpIndex = 0;
                Pos = 100;
                Timer T = new Timer();
                T.Interval = 10;
                T.Tick += new EventHandler(T_Tick);
                T.Enabled = true;
            }        private void button2_Click(object sender, EventArgs e)
            {
                PB.ImageLocation = "";
                Timer t = new Timer();
                t.Enabled = false;
            }
        }}
      

  4.   


    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;namespace test
    {
        public partial class testForm : Form
        {
            private Panel pan_picpan = new Panel();
            private PictureBox pictureBox1 = new PictureBox();
            private PictureBox pictureBox2 = new PictureBox();
            private System.Timers.Timer m_timer = new System.Timers.Timer();
            public testForm()
            {
                Control.CheckForIllegalCrossThreadCalls = false;
                
                MyInitializeComponent();
                m_timer = new System.Timers.Timer(50);//间隔时间
                m_timer.Elapsed += new System.Timers.ElapsedEventHandler(this.mainLoop);
                m_timer.AutoReset = true;
                m_timer.Enabled = true;
                m_timer.Start();
            }        private void MyInitializeComponent() {
                this.SuspendLayout();
                // 
                // pan_picpan
                // 
                this.pan_picpan.Controls.Add(this.pictureBox2);
                this.pan_picpan.Controls.Add(this.pictureBox1);
                this.pan_picpan.Location = new System.Drawing.Point(101, 80);
                this.pan_picpan.Name = "pan_picpan";
                this.pan_picpan.Size = new System.Drawing.Size(100, 100);
                this.pan_picpan.TabIndex = 0;
                // 
                // pictureBox1
                // 
                this.pictureBox1.Location = new System.Drawing.Point(0, 0);
                this.pictureBox1.Name = "pictureBox1";
                this.pictureBox1.Size = new System.Drawing.Size(100, 100);
                this.pictureBox1.TabIndex = 0;
                this.pictureBox1.TabStop = false;
                this.pictureBox1.Image = Image.FromFile(@"C:\TFS\Testsql\a.jpg");
                // 
                // pictureBox2
                // 
                this.pictureBox2.Location = new System.Drawing.Point(100, 0);
                this.pictureBox2.Name = "pictureBox2";
                this.pictureBox2.Size = new System.Drawing.Size(100, 100);
                this.pictureBox2.TabIndex = 1;
                this.pictureBox2.TabStop = false;
                this.pictureBox2.Image = Image.FromFile(@"C:\TFS\Testsql\b.jpg");
                // 
                // testForm
                // 
                this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                this.ClientSize = new System.Drawing.Size(292, 273);
                this.Name = "testForm";
                this.Text = "testForm";
                this.ResumeLayout(false);
                this.Controls.Add(this.pan_picpan);        }
            private void mainLoop(object source, System.Timers.ElapsedEventArgs e)
            {
                MovePictureBox(pictureBox1);
                MovePictureBox(pictureBox2);
            }
            private void MovePictureBox(PictureBox pictureBox) {
                Point p = pictureBox.Location;
                if (p.X >= -100)//你的panel的宽度
                {
                    p.X -= 1;
                }
                else
                {
                    p.X += 200;
                }
                pictureBox.Location = p;
            }
        }
    }