winform 三个Panel左右切换(panel里面填充图片)

    //Panel重写(不闪烁)

     public class BackgroundPanel : Panel
     {
        public BackgroundPanel()
        {
            this.SetStyle(ControlStyles.AllPaintingInWmPaint |          //不擦除背景 ,减少闪烁
                          ControlStyles.OptimizedDoubleBuffer |         //双缓冲
                          ControlStyles.UserPaint,                      //使用自定义的重绘事件,减少闪烁
                          true);                                        //设置值

        }

     }

//页面布局

  partial class test2
     {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.PnlPageTwo = new ParkingInquire.PublicClass.BackgroundPanel();
            this.PnlPicPageTwo1 = new ParkingInquire.PublicClass.BackgroundPanel();
            this.PicCarOne_Pnl1 = new System.Windows.Forms.PictureBox();
            this.PicCarTwo_Pnl1 = new System.Windows.Forms.PictureBox();
            this.PicCarThree_Pnl1 = new System.Windows.Forms.PictureBox();
            this.PicCarFour_Pnl1 = new System.Windows.Forms.PictureBox();
            this.PicCarFive_Pnl1 = new System.Windows.Forms.PictureBox();
            this.PicCarSix_Pnl1 = new System.Windows.Forms.PictureBox();
            this.PnlPicPageTwo2 = new ParkingInquire.PublicClass.BackgroundPanel();
            this.PicCarOne_Pnl2 = new System.Windows.Forms.PictureBox();
            this.PicCarTwo_Pnl2 = new System.Windows.Forms.PictureBox();
            this.PicCarThree_Pnl2 = new System.Windows.Forms.PictureBox();
            this.PicCarFour_Pnl2 = new System.Windows.Forms.PictureBox();
            this.PicCarFive_Pnl2 = new System.Windows.Forms.PictureBox();
            this.PicCarSix_Pnl2 = new System.Windows.Forms.PictureBox();
            this.PnlPicPageTwo3 = new ParkingInquire.PublicClass.BackgroundPanel();
            this.PicCarOne_Pnl3 = new System.Windows.Forms.PictureBox();
            this.PicCarTwo_Pnl3 = new System.Windows.Forms.PictureBox();
            this.PicCarThree_Pnl3 = new System.Windows.Forms.PictureBox();
            this.PicCarFour_Pnl3 = new System.Windows.Forms.PictureBox();
            this.PicCarFive_Pnl3 = new System.Windows.Forms.PictureBox();
            this.PicCarSix_Pnl3 = new System.Windows.Forms.PictureBox();

            /*this.labCarNoOne_pnl2 = new System.Windows.Forms.Label();
            this.labCarNoTwo_pnl2 = new System.Windows.Forms.Label();
            this.labCarNoThree_pnl2 = new System.Windows.Forms.Label();
            this.labCarNoFour_pnl2 = new System.Windows.Forms.Label();
            this.labCarNoFive_pnl2 = new System.Windows.Forms.Label();
            this.labCarNoSix_pnl2 = new System.Windows.Forms.Label();*/
            this.PnlPageTwo.SuspendLayout();
            this.PnlPicPageTwo1.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.PicCarOne_Pnl1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.PicCarTwo_Pnl1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.PicCarThree_Pnl1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.PicCarFour_Pnl1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.PicCarFive_Pnl1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.PicCarSix_Pnl1)).BeginInit();
            this.PnlPicPageTwo2.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.PicCarOne_Pnl2)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.PicCarTwo_Pnl2)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.PicCarThree_Pnl2)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.PicCarFour_Pnl2)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.PicCarFive_Pnl2)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.PicCarSix_Pnl2)).BeginInit();
            this.PnlPicPageTwo3.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.PicCarOne_Pnl3)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.PicCarTwo_Pnl3)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.PicCarThree_Pnl3)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.PicCarFour_Pnl3)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.PicCarFive_Pnl3)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.PicCarSix_Pnl3)).BeginInit();
            this.SuspendLayout();
            //
            // PnlPageTwo
            //
            this.PnlPageTwo.Controls.Add(this.PnlPicPageTwo1);
            this.PnlPageTwo.Controls.Add(this.PnlPicPageTwo2);
            this.PnlPageTwo.Controls.Add(this.PnlPicPageTwo3);
            this.PnlPageTwo.Location = new System.Drawing.Point(15, 15);
            this.PnlPageTwo.Name = "PnlPageTwo";
            this.PnlPageTwo.Size = new System.Drawing.Size(500, 350);
            this.PnlPageTwo.TabIndex = 0;
            //
            // PicCarOne_Pnl1
            //
            this.PicCarOne_Pnl1.BackColor = System.Drawing.Color.Blue;
            this.PicCarOne_Pnl1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
            this.PicCarOne_Pnl1.ErrorImage = null;
            this.PicCarOne_Pnl1.Location = new System.Drawing.Point(0, 0);
            this.PicCarOne_Pnl1.Name = "PicCarOne_Pnl1";
            this.PicCarOne_Pnl1.Size = new System.Drawing.Size(160, 125);
            this.PicCarOne_Pnl1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
            this.PicCarOne_Pnl1.TabIndex = 8;
            this.PicCarOne_Pnl1.TabStop = false;
            this.PicCarOne_Pnl1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseDown);
            this.PicCarOne_Pnl1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseMove);
            this.PicCarOne_Pnl1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseUp);
            //
            // PicCarTwo_Pnl1
            //
            this.PicCarTwo_Pnl1.BackColor = System.Drawing.Color.Blue;
            this.PicCarTwo_Pnl1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
            this.PicCarTwo_Pnl1.ErrorImage = null;
            this.PicCarTwo_Pnl1.Location = new System.Drawing.Point(0, 135);
            this.PicCarTwo_Pnl1.Name = "PicCarTwo_Pnl1";
            this.PicCarTwo_Pnl1.Size = new System.Drawing.Size(160, 125);
            this.PicCarTwo_Pnl1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
            this.PicCarTwo_Pnl1.TabIndex = 9;
            this.PicCarTwo_Pnl1.TabStop = false;
            this.PicCarTwo_Pnl1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseDown);
            this.PicCarTwo_Pnl1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseMove);
            this.PicCarTwo_Pnl1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseUp);
            //
            // PicCarThree_Pnl1
            //
            this.PicCarThree_Pnl1.BackColor = System.Drawing.Color.Blue;
            this.PicCarThree_Pnl1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
            this.PicCarThree_Pnl1.ErrorImage = null;
            this.PicCarThree_Pnl1.Location = new System.Drawing.Point(170, 0);
            this.PicCarThree_Pnl1.Name = "PicCarThree_Pnl1";
            this.PicCarThree_Pnl1.Size = new System.Drawing.Size(160, 125);
            this.PicCarThree_Pnl1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
            this.PicCarThree_Pnl1.TabIndex = 10;
            this.PicCarThree_Pnl1.TabStop = false;
            this.PicCarThree_Pnl1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseDown);
            this.PicCarThree_Pnl1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseMove);
            this.PicCarThree_Pnl1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseUp);
            //
            // PicCarFour_Pnl1
            //
            this.PicCarFour_Pnl1.BackColor = System.Drawing.Color.Blue;
            this.PicCarFour_Pnl1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
            this.PicCarFour_Pnl1.ErrorImage = null;
            this.PicCarFour_Pnl1.Location = new System.Drawing.Point(170, 135);
            this.PicCarFour_Pnl1.Name = "PicCarFour_Pnl1";
            this.PicCarFour_Pnl1.Size = new System.Drawing.Size(160, 125);
            this.PicCarFour_Pnl1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
            this.PicCarFour_Pnl1.TabIndex = 11;
            this.PicCarFour_Pnl1.TabStop = false;
            this.PicCarFour_Pnl1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseDown);
            this.PicCarFour_Pnl1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseMove);
            this.PicCarFour_Pnl1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseUp);
            //
            // PicCarFive_Pnl1
            //
            this.PicCarFive_Pnl1.BackColor = System.Drawing.Color.Blue;
            this.PicCarFive_Pnl1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
            this.PicCarFive_Pnl1.ErrorImage = null;
            this.PicCarFive_Pnl1.Location = new System.Drawing.Point(340, 0);
            this.PicCarFive_Pnl1.Name = "PicCarFive_Pnl1";
            this.PicCarFive_Pnl1.Size = new System.Drawing.Size(160, 125);
            this.PicCarFive_Pnl1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
            this.PicCarFive_Pnl1.TabIndex = 12;
            this.PicCarFive_Pnl1.TabStop = false;
            this.PicCarFive_Pnl1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseDown);
            this.PicCarFive_Pnl1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseMove);
            this.PicCarFive_Pnl1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseUp);
            //
            // PicCarSix_Pnl1
            //
            this.PicCarSix_Pnl1.BackColor = System.Drawing.Color.Blue;
            this.PicCarSix_Pnl1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
            this.PicCarSix_Pnl1.ErrorImage = null;
            this.PicCarSix_Pnl1.Location = new System.Drawing.Point(340, 135);
            this.PicCarSix_Pnl1.Name = "PicCarSix_Pnl1";
            this.PicCarSix_Pnl1.Size = new System.Drawing.Size(160, 125);
            this.PicCarSix_Pnl1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
            this.PicCarSix_Pnl1.TabIndex = 13;
            this.PicCarSix_Pnl1.TabStop = false;
            this.PicCarSix_Pnl1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseDown);
            this.PicCarSix_Pnl1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseMove);
            this.PicCarSix_Pnl1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseUp);
            //
            // PnlPicPageTwo1
            //
            this.PnlPicPageTwo1.BackColor = System.Drawing.Color.Beige;
            this.PnlPicPageTwo1.Controls.Add(this.PicCarOne_Pnl1);
            this.PnlPicPageTwo1.Controls.Add(this.PicCarTwo_Pnl1);
            this.PnlPicPageTwo1.Controls.Add(this.PicCarThree_Pnl1);
            this.PnlPicPageTwo1.Controls.Add(this.PicCarFour_Pnl1);
            this.PnlPicPageTwo1.Controls.Add(this.PicCarFive_Pnl1);
            this.PnlPicPageTwo1.Controls.Add(this.PicCarSix_Pnl1);
            this.PnlPicPageTwo1.Location = new System.Drawing.Point(40, 40);
            this.PnlPicPageTwo1.Name = "PnlPicPageTwo1";
            this.PnlPicPageTwo1.Size = new System.Drawing.Size(500, 260);
            this.PnlPicPageTwo1.TabIndex = 1;
            this.PnlPicPageTwo1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseDown);
            this.PnlPicPageTwo1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseMove);
            this.PnlPicPageTwo1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseUp);
            //
            // PicCarOne_Pnl2
            //
            this.PicCarOne_Pnl2.BackColor = System.Drawing.Color.Brown;
            this.PicCarOne_Pnl2.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
            this.PicCarOne_Pnl2.ErrorImage = null;
            this.PicCarOne_Pnl2.Location = new System.Drawing.Point(0, 0);
            this.PicCarOne_Pnl2.Name = "PicCarOne_Pnl2";
            this.PicCarOne_Pnl2.Size = new System.Drawing.Size(160, 125);
            this.PicCarOne_Pnl2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
            this.PicCarOne_Pnl2.TabIndex = 2;
            this.PicCarOne_Pnl2.TabStop = false;
            this.PicCarOne_Pnl2.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseDown);
            this.PicCarOne_Pnl2.MouseMove += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseMove);
            this.PicCarOne_Pnl2.MouseUp += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseUp);
            //
            // PicCarTwo_Pnl2
            //
            this.PicCarTwo_Pnl2.BackColor = System.Drawing.Color.Brown;
            this.PicCarTwo_Pnl2.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
            this.PicCarTwo_Pnl2.ErrorImage = null;
            this.PicCarTwo_Pnl2.Location = new System.Drawing.Point(0, 135);
            this.PicCarTwo_Pnl2.Name = "PicCarTwo_Pnl2";
            this.PicCarTwo_Pnl2.Size = new System.Drawing.Size(160, 125);
            this.PicCarTwo_Pnl2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
            this.PicCarTwo_Pnl2.TabIndex = 3;
            this.PicCarTwo_Pnl2.TabStop = false;
            this.PicCarTwo_Pnl2.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseDown);
            this.PicCarTwo_Pnl2.MouseMove += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseMove);
            this.PicCarTwo_Pnl2.MouseUp += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseUp);
            //
            // PicCarThree_Pnl2
            //
            this.PicCarThree_Pnl2.BackColor = System.Drawing.Color.Brown;
            this.PicCarThree_Pnl2.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
            this.PicCarThree_Pnl2.ErrorImage = null;
            this.PicCarThree_Pnl2.Location = new System.Drawing.Point(170, 0);
            this.PicCarThree_Pnl2.Name = "PicCarThree_Pnl2";
            this.PicCarThree_Pnl2.Size = new System.Drawing.Size(160, 125);
            this.PicCarThree_Pnl2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
            this.PicCarThree_Pnl2.TabIndex = 4;
            this.PicCarThree_Pnl2.TabStop = false;
            this.PicCarThree_Pnl2.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseDown);
            this.PicCarThree_Pnl2.MouseMove += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseMove);
            this.PicCarThree_Pnl2.MouseUp += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseUp);
            //
            // PicCarFour_Pnl2
            //
            this.PicCarFour_Pnl2.BackColor = System.Drawing.Color.Brown;
            this.PicCarFour_Pnl2.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
            this.PicCarFour_Pnl2.ErrorImage = null;
            this.PicCarFour_Pnl2.Location = new System.Drawing.Point(170, 135);
            this.PicCarFour_Pnl2.Name = "PicCarFour_Pnl2";
            this.PicCarFour_Pnl2.Size = new System.Drawing.Size(160, 125);
            this.PicCarFour_Pnl2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
            this.PicCarFour_Pnl2.TabIndex = 5;
            this.PicCarFour_Pnl2.TabStop = false;
            this.PicCarFour_Pnl2.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseDown);
            this.PicCarFour_Pnl2.MouseMove += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseMove);
            this.PicCarFour_Pnl2.MouseUp += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseUp);
            //
            // PicCarFive_Pnl2
            //
            this.PicCarFive_Pnl2.BackColor = System.Drawing.Color.Brown;
            this.PicCarFive_Pnl2.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
            this.PicCarFive_Pnl2.ErrorImage = null;
            this.PicCarFive_Pnl2.Location = new System.Drawing.Point(340, 0);
            this.PicCarFive_Pnl2.Name = "PicCarFive_Pnl2";
            this.PicCarFive_Pnl2.Size = new System.Drawing.Size(160, 125);
            this.PicCarFive_Pnl2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
            this.PicCarFive_Pnl2.TabIndex = 6;
            this.PicCarFive_Pnl2.TabStop = false;
            this.PicCarFive_Pnl2.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseDown);
            this.PicCarFive_Pnl2.MouseMove += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseMove);
            this.PicCarFive_Pnl2.MouseUp += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseUp);
            //
            // PicCarSix_Pnl2
            //
            this.PicCarSix_Pnl2.BackColor = System.Drawing.Color.Brown;
            this.PicCarSix_Pnl2.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
            this.PicCarSix_Pnl2.ErrorImage = null;
            this.PicCarSix_Pnl2.Location = new System.Drawing.Point(340, 135);
            this.PicCarSix_Pnl2.Name = "PicCarSix_Pnl2";
            this.PicCarSix_Pnl2.Size = new System.Drawing.Size(160, 125);
            this.PicCarSix_Pnl2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
            this.PicCarSix_Pnl2.TabIndex = 7;
            this.PicCarSix_Pnl2.TabStop = false;
            this.PicCarSix_Pnl2.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseDown);
            this.PicCarSix_Pnl2.MouseMove += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseMove);
            this.PicCarSix_Pnl2.MouseUp += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseUp);
            //
            // PnlPicPageTwo2
            //
            this.PnlPicPageTwo2.BackColor = System.Drawing.Color.Aquamarine;
            this.PnlPicPageTwo2.Controls.Add(this.PicCarOne_Pnl2);
            this.PnlPicPageTwo2.Controls.Add(this.PicCarTwo_Pnl2);
            this.PnlPicPageTwo2.Controls.Add(this.PicCarThree_Pnl2);
            this.PnlPicPageTwo2.Controls.Add(this.PicCarFour_Pnl2);
            this.PnlPicPageTwo2.Controls.Add(this.PicCarFive_Pnl2);
            this.PnlPicPageTwo2.Controls.Add(this.PicCarSix_Pnl2);
            this.PnlPicPageTwo2.Location = new System.Drawing.Point(20, 60);
            this.PnlPicPageTwo2.Name = "PnlPicPageTwo2";
            this.PnlPicPageTwo2.Size = new System.Drawing.Size(500, 260);
            this.PnlPicPageTwo2.TabIndex = 1;
            this.PnlPicPageTwo2.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseDown);
            this.PnlPicPageTwo2.MouseMove += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseMove);
            this.PnlPicPageTwo2.MouseUp += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseUp);
            //
            // PicCarOne_Pnl3
            //
            this.PicCarOne_Pnl3.BackColor = System.Drawing.Color.Transparent;
            this.PicCarOne_Pnl3.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
            this.PicCarOne_Pnl3.ErrorImage = null;
            this.PicCarOne_Pnl3.Location = new System.Drawing.Point(0, 0);
            this.PicCarOne_Pnl3.Name = "PicCarOne_Pnl3";
            this.PicCarOne_Pnl3.Size = new System.Drawing.Size(160, 125);
            this.PicCarOne_Pnl3.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
            this.PicCarOne_Pnl3.TabIndex = 14;
            this.PicCarOne_Pnl3.TabStop = false;
            this.PicCarOne_Pnl3.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseDown);
            this.PicCarOne_Pnl3.MouseMove += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseMove);
            this.PicCarOne_Pnl3.MouseUp += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseUp);
            //
            // PicCarTwo_Pnl3
            //
            this.PicCarTwo_Pnl3.BackColor = System.Drawing.Color.Transparent;
            this.PicCarTwo_Pnl3.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
            this.PicCarTwo_Pnl3.ErrorImage = null;
            this.PicCarTwo_Pnl3.Location = new System.Drawing.Point(0, 135);
            this.PicCarTwo_Pnl3.Name = "PicCarTwo_Pnl3";
            this.PicCarTwo_Pnl3.Size = new System.Drawing.Size(160, 125);
            this.PicCarTwo_Pnl3.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
            this.PicCarTwo_Pnl3.TabIndex = 15;
            this.PicCarTwo_Pnl3.TabStop = false;
            this.PicCarTwo_Pnl3.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseDown);
            this.PicCarTwo_Pnl3.MouseMove += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseMove);
            this.PicCarTwo_Pnl3.MouseUp += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseUp);
            //
            // PicCarThree_Pnl3
            //
            this.PicCarThree_Pnl3.BackColor = System.Drawing.Color.Transparent;
            this.PicCarThree_Pnl3.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
            this.PicCarThree_Pnl3.ErrorImage = null;
            this.PicCarThree_Pnl3.Location = new System.Drawing.Point(170, 0);
            this.PicCarThree_Pnl3.Name = "PicCarThree_Pnl3";
            this.PicCarThree_Pnl3.Size = new System.Drawing.Size(160, 125);
            this.PicCarThree_Pnl3.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
            this.PicCarThree_Pnl3.TabIndex = 16;
            this.PicCarThree_Pnl3.TabStop = false;
            this.PicCarThree_Pnl3.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseDown);
            this.PicCarThree_Pnl3.MouseMove += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseMove);
            this.PicCarThree_Pnl3.MouseUp += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseUp);
            //
            // PicCarFour_Pnl3
            //
            this.PicCarFour_Pnl3.BackColor = System.Drawing.Color.Transparent;
            this.PicCarFour_Pnl3.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
            this.PicCarFour_Pnl3.ErrorImage = null;
            this.PicCarFour_Pnl3.Location = new System.Drawing.Point(170, 135);
            this.PicCarFour_Pnl3.Name = "PicCarFour_Pnl3";
            this.PicCarFour_Pnl3.Size = new System.Drawing.Size(160, 125);
            this.PicCarFour_Pnl3.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
            this.PicCarFour_Pnl3.TabIndex = 17;
            this.PicCarFour_Pnl3.TabStop = false;
            this.PicCarFour_Pnl3.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseDown);
            this.PicCarFour_Pnl3.MouseMove += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseMove);
            this.PicCarFour_Pnl3.MouseUp += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseUp);
            //
            // PicCarFive_Pnl3
            //
            this.PicCarFive_Pnl3.BackColor = System.Drawing.Color.Transparent;
            this.PicCarFive_Pnl3.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
            this.PicCarFive_Pnl3.ErrorImage = null;
            this.PicCarFive_Pnl3.Location = new System.Drawing.Point(340, 0);
            this.PicCarFive_Pnl3.Name = "PicCarFive_Pnl3";
            this.PicCarFive_Pnl3.Size = new System.Drawing.Size(160, 125);
            this.PicCarFive_Pnl3.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
            this.PicCarFive_Pnl3.TabIndex = 18;
            this.PicCarFive_Pnl3.TabStop = false;
            this.PicCarFive_Pnl3.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseDown);
            this.PicCarFive_Pnl3.MouseMove += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseMove);
            this.PicCarFive_Pnl3.MouseUp += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseUp);
            //
            // PicCarSix_Pnl3
            //
            this.PicCarSix_Pnl3.BackColor = System.Drawing.Color.Transparent;
            this.PicCarSix_Pnl3.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
            this.PicCarSix_Pnl3.ErrorImage = null;
            this.PicCarSix_Pnl3.Location = new System.Drawing.Point(340, 135);
            this.PicCarSix_Pnl3.Name = "PicCarSix_Pnl3";
            this.PicCarSix_Pnl3.Size = new System.Drawing.Size(160, 125);
            this.PicCarSix_Pnl3.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
            this.PicCarSix_Pnl3.TabIndex = 19;
            this.PicCarSix_Pnl3.TabStop = false;
            this.PicCarSix_Pnl3.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseDown);
            this.PicCarSix_Pnl3.MouseMove += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseMove);
            this.PicCarSix_Pnl3.MouseUp += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseUp);
            //
            // PnlPicPageTwo3
            //
            this.PnlPicPageTwo3.BackColor = System.Drawing.Color.AliceBlue;
            this.PnlPicPageTwo3.Controls.Add(this.PicCarOne_Pnl3);
            this.PnlPicPageTwo3.Controls.Add(this.PicCarTwo_Pnl3);
            this.PnlPicPageTwo3.Controls.Add(this.PicCarThree_Pnl3);
            this.PnlPicPageTwo3.Controls.Add(this.PicCarFour_Pnl3);
            this.PnlPicPageTwo3.Controls.Add(this.PicCarFive_Pnl3);
            this.PnlPicPageTwo3.Controls.Add(this.PicCarSix_Pnl3);
            this.PnlPicPageTwo3.Location = new System.Drawing.Point(60, 20);
            this.PnlPicPageTwo3.Name = "PnlPicPageTwo3";
            this.PnlPicPageTwo3.Size = new System.Drawing.Size(500, 260);
            this.PnlPicPageTwo3.TabIndex = 20;
            this.PnlPicPageTwo3.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseDown);
            this.PnlPicPageTwo3.MouseMove += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseMove);
            this.PnlPicPageTwo3.MouseUp += new System.Windows.Forms.MouseEventHandler(this.PnlPicPage_MouseUp);
           
            //
            // test2
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(660, 380);
            this.Controls.Add(this.PnlPageTwo);
            this.Name = "test2";
            this.Text = "test2";
            this.PnlPageTwo.ResumeLayout(false);
            this.PnlPageTwo.PerformLayout();
            this.PnlPicPageTwo1.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.PicCarOne_Pnl1)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.PicCarTwo_Pnl1)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.PicCarThree_Pnl1)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.PicCarFour_Pnl1)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.PicCarFive_Pnl1)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.PicCarSix_Pnl1)).EndInit();
            this.PnlPicPageTwo2.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.PicCarOne_Pnl2)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.PicCarTwo_Pnl2)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.PicCarThree_Pnl2)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.PicCarFour_Pnl2)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.PicCarFive_Pnl2)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.PicCarSix_Pnl2)).EndInit();
            this.PnlPicPageTwo3.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.PicCarOne_Pnl3)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.PicCarTwo_Pnl3)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.PicCarThree_Pnl3)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.PicCarFour_Pnl3)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.PicCarFive_Pnl3)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.PicCarSix_Pnl3)).EndInit();
            this.ResumeLayout(false);

        }

        #endregion

        private BackgroundPanel PnlPageTwo;
        private BackgroundPanel PnlPicPageTwo1;
        private BackgroundPanel PnlPicPageTwo2;
        private BackgroundPanel PnlPicPageTwo3;
        private System.Windows.Forms.PictureBox PicCarOne_Pnl1;
        private System.Windows.Forms.PictureBox PicCarTwo_Pnl1;
        private System.Windows.Forms.PictureBox PicCarThree_Pnl1;
        private System.Windows.Forms.PictureBox PicCarFour_Pnl1;
        private System.Windows.Forms.PictureBox PicCarFive_Pnl1;
        private System.Windows.Forms.PictureBox PicCarSix_Pnl1;
        private System.Windows.Forms.PictureBox PicCarOne_Pnl2;
        private System.Windows.Forms.PictureBox PicCarTwo_Pnl2;
        private System.Windows.Forms.PictureBox PicCarThree_Pnl2;
        private System.Windows.Forms.PictureBox PicCarFour_Pnl2;
        private System.Windows.Forms.PictureBox PicCarFive_Pnl2;
        private System.Windows.Forms.PictureBox PicCarSix_Pnl2;
        private System.Windows.Forms.PictureBox PicCarOne_Pnl3;
        private System.Windows.Forms.PictureBox PicCarTwo_Pnl3;
        private System.Windows.Forms.PictureBox PicCarThree_Pnl3;
        private System.Windows.Forms.PictureBox PicCarFour_Pnl3;
        private System.Windows.Forms.PictureBox PicCarFive_Pnl3;
        private System.Windows.Forms.PictureBox PicCarSix_Pnl3;

   }

//cs

  public partial class test2 : Form
     {
        /// <summary>
        /// 是否显示鼠标
        /// </summary>
        /// <param name="bShow"></param>
        /// <returns></returns>
        [DllImport("user32.dll", EntryPoint = "ShowCursor")]
        static extern bool ShowCursor_WIN(bool bShow);
        /// <summary>
        /// 设置鼠标位置
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        [System.Runtime.InteropServices.DllImport("user32.dll")]
        public static extern int SetCursorPos(int x, int y);
        /// <summary>
        /// 得到鼠标位置
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        [System.Runtime.InteropServices.DllImport("user32.dll")]
        public static extern int GetCursorPos(ref Point mouse_p);

        /// <summary>
        /// 鼠标按下时橫坐标位置
        /// </summary>
        int mouseDownX;
        /// <summary>
        /// 系统睡眠时间
        /// </summary>
        int threadSleep;
        /// <summary>
        /// 查询出来的车位照片
        /// </summary>
        List<Image> carImage = new List<Image>();
        /// <summary>
        /// 一页显示多少车辆照片
        /// </summary>
        int pnlPicAmount;
        /// <summary>
        /// 左边的pnl显示的车辆照片起始下标
        /// </summary>
        int leftPnlIndex;
        /// <summary>
        /// 右边的Pnl显示的车辆照片起始下标
        /// </summary>
        int rightPnlIndex;
        /// <summary>
        /// 车位Id
        /// </summary>
        List<int> carParkingId = new List<int>();
        /// <summary>
        /// FTP车子照片路径
        /// </summary>
        string FtpPicPath;
        /// <summary>
        /// FTP 用户名
        /// </summary>
        string FtpUser;
        /// <summary>
        /// 记录鼠标的x坐标和y坐标
        /// </summary>
        int x, y;

        public test2()
        {
            InitializeComponent();
            x = Control.MousePosition.X;
            y = Control.MousePosition.Y;
            this.Load +=new EventHandler(test2_Load);
            PicCarOne_Pnl2.MouseDoubleClick+=new MouseEventHandler(PnlPic_MouseDoubleClick);
        }
        private void test2_Load(object sender, EventArgs e)
        {

            ShowCursor_WIN(true);

            threadSleep = 50;
            FtpPicPath = "";
            FtpUser = "";

            pnlPicBack(PnlPicPageTwo1, PnlPicPageTwo2, PnlPicPageTwo3);///车位照片pnl 重置位置
            ///计算一页显示车位为几乘几
            pnlPicAmount = 6;///暂时固定一页显示 6个车位
            leftPnlIndex = 0;
            rightPnlIndex = pnlPicAmount;

            this.SetStyle(ControlStyles.UserPaint, true);                       ///自绘
            this.SetStyle(ControlStyles.DoubleBuffer, true);                    ///双缓冲
            this.SetStyle(ControlStyles.ResizeRedraw, true);                    ///调整大小时重绘
            this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);            ///禁止擦除背景.
            this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);           ///双缓冲
            this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);    ///透明效果
            this.InitData();
            FillPic(6, 6, 6);                                             
        }
        List<Image> ls_images = new List<Image>();    //存放图片组
        private void InitData()
        {
            int i = 0;
            string[] str_paths = Directory.GetFiles(string.Format("{0}/Images", Application.StartupPath), "*.jpg");
            foreach (string path in str_paths)
            {
                ls_images.Add(Image.FromFile(path));
                carParkingId.Add(i++);
            }
            carImage = ls_images;
        }

        /// <summary>
        /// 根据ParkingId列表 得到 车位照片
        /// </summary>
        /// <param name="license"></param>
        public void GetPicByParkingId(List<int> parkingId, List<string> imgName)
        {
            carImage.Clear(); carParkingId.Clear();///清空车位图片信息
            ///读取FTP相应图片到List
            for (int i = 0; i < imgName.Count; i++)
            {
                try
                {
                    FtpWebRequest fwRequest = (FtpWebRequest)FtpWebRequest.Create(new Uri(FtpPicPath + imgName[i]));///创建FTP请求对象
                    fwRequest.KeepAlive = false;                                        ///设置请求完成后关闭此连接
                    fwRequest.Method = WebRequestMethods.Ftp.DownloadFile;              ///设置到FTP的命令为下载文件
                    fwRequest.Credentials = new NetworkCredential(FtpUser, "lf0507");   ///设置Ftp客户端访问的通讯凭据;
                    fwRequest.UseBinary = true;                                         ///设置数据传输类型
                    FtpWebResponse fwRsponse = (FtpWebResponse)fwRequest.GetResponse(); ///获取Ftp响应
                    Stream stream = fwRsponse.GetResponseStream();                      ///从返回流中检索数据
                    carImage.Add(Image.FromStream(stream));                             ///将流数据转换成图片 加入List
                    carParkingId.Add(parkingId[i]);                                     ///车位Id加入List
                    stream.Dispose();                                                   ///数据流释放
                    stream.Close();                                                     ///数据流关闭
                    fwRsponse.Close();                                                  ///释放资源
                }
                catch (Exception e)
                {
                    throw new Exception(e.Message);
                }
            }
        }

        /// <summary>
        /// 照片 pnl 移动
        /// </summary>
        /// <param name="outPanel">要移出的Panel</param>
        /// <param name="inPanel">移入(X轴置0)</param>
        /// <param name="ReSetPanel">需要重置位置的Panel</param>
        /// <param name="type">-1往前移,1为往后移</param>
        public void PanelPicMove(Panel outPanel, Panel inPanel, Panel ReSetPanel, int type)
        {
            int moveX = 80;///每次移动的像素
            if (type == -1)
            {
                while (inPanel.Location.X > moveX)
                {
                    outPanel.Left = outPanel.Location.X - moveX;
                    inPanel.Left  = inPanel.Location.X - moveX;
                    Thread.Sleep(threadSleep * 4);
                    PnlPageTwo.Update();
                }
                outPanel.Left   = 0 - outPanel.Width;
                inPanel.Left    = 0;
                ReSetPanel.Left = 0 + ReSetPanel.Width;
            }
            else if (type == 1)
            {
                while (inPanel.Location.X < -moveX)
                {
                    outPanel.Left = outPanel.Location.X + moveX;
                    inPanel.Left  = inPanel.Location.X + moveX;
                    Thread.Sleep(threadSleep * 4);
                    PnlPageTwo.Update();
                }
                outPanel.Left   = 0 + outPanel.Width;
                inPanel.Left    = 0;
                ReSetPanel.Left = 0 - ReSetPanel.Width;
            }
        }

        /// <summary>
        ///  鼠标滑动 移动整个pnl
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void PnlPicPage_MouseMove(object sender, MouseEventArgs e)
        {
            if (mouseDownX != 0) ///表示以按下
            {
                Point cursorPosMoved = new Point();
                GetCursorPos(ref cursorPosMoved);
                PnlPicPageTwo1.Left = PnlPicPageTwo1.Location.X - (mouseDownX - cursorPosMoved.X);
                PnlPicPageTwo2.Left = PnlPicPageTwo2.Location.X - (mouseDownX - cursorPosMoved.X);
                PnlPicPageTwo3.Left = PnlPicPageTwo3.Location.X - (mouseDownX - cursorPosMoved.X);
                PnlPageTwo.Update();
                mouseDownX = cursorPosMoved.X;///记录当前鼠标位置
            }
        }
        /// <summary>
        /// 鼠标按下记录坐标
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void PnlPicPage_MouseDown(object sender, MouseEventArgs e)
        {
            Point cursorPos = new Point();
            GetCursorPos(ref cursorPos);
            mouseDownX = cursorPos.X;
        }

        /// <summary>
        /// 鼠标抬起 查看坐标是否与按下时有偏移
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void PnlPicPage_MouseUp(object sender, MouseEventArgs e)
        {
            int changeX = 5;   ///在指定偏移像素内不做移动操作
            ///找到左中右的panel
            ParkingInquire.PublicClass.BackgroundPanel pnlRight  = new ParkingInquire.PublicClass.BackgroundPanel();
            ParkingInquire.PublicClass.BackgroundPanel pnlLeft   = new ParkingInquire.PublicClass.BackgroundPanel();
            ParkingInquire.PublicClass.BackgroundPanel pnlCenter = new ParkingInquire.PublicClass.BackgroundPanel();
            if (PnlPicPageTwo1.Location.X > PnlPicPageTwo2.Location.X)
            {
                if (PnlPicPageTwo1.Location.X > PnlPicPageTwo3.Location.X)
                {
                    pnlRight = PnlPicPageTwo1;
                    if (PnlPicPageTwo2.Location.X > PnlPicPageTwo3.Location.X)
                    {
                        pnlCenter = PnlPicPageTwo2;
                        pnlLeft   = PnlPicPageTwo3;
                    }
                    else
                    {
                        pnlCenter = PnlPicPageTwo3;
                        pnlLeft   = PnlPicPageTwo2;
                    }
                }
                else
                {
                    pnlCenter = PnlPicPageTwo1;
                    pnlLeft   = PnlPicPageTwo2;
                    pnlRight  = PnlPicPageTwo3;
                }
            }
            else
            {
                if (PnlPicPageTwo1.Location.X < PnlPicPageTwo3.Location.X)
                {
                    pnlLeft = PnlPicPageTwo1;
                    if (PnlPicPageTwo2.Location.X > PnlPicPageTwo3.Location.X)
                    {
                        pnlCenter = PnlPicPageTwo3;
                        pnlRight  = PnlPicPageTwo2;
                    }
                    else
                    {
                        pnlCenter = PnlPicPageTwo2;
                        pnlRight  = PnlPicPageTwo3;
                    }
                }
                else
                {
                    pnlCenter = PnlPicPageTwo1;
                    pnlLeft   = PnlPicPageTwo3;
                    pnlRight  = PnlPicPageTwo2;
                }
            }

            if (Math.Abs(pnlCenter.Location.X) > changeX)
            {
                if (pnlCenter.Location.X < 0)///鼠标向左移了
                {
                    if (!pnlHasPic(pnlRight))///如果pnlRight一张图片都 没有 则pnlCenter 回原位  无需换图片数据
                    {
                        PanelPicMove(pnlRight, pnlCenter, pnlLeft, 1);
                    }
                    else
                    {
                        PanelPicMove(pnlCenter, pnlRight, pnlLeft, -1);
                        if (pnlHasPic(pnlLeft))
                            leftPnlIndex  += pnlPicAmount;///如果左边pnl不为空..则左pnl起始地址增加
                        if (rightPnlIndex + pnlPicAmount + 1 > carImage.Count)
                        {
                            FillPnlPic(pnlLeft, 0, 0);
                        }
                        else
                        {
                            rightPnlIndex += pnlPicAmount;///如果右panel有照片填了 则右起始地址增加
                            FillPnlPic(pnlLeft, rightPnlIndex, pnlPicAmount);
                        }
                    }
                }
                else if (pnlCenter.Location.X > 0) ///鼠标向右移了
                {
                    if (!pnlHasPic(pnlLeft))///如果pnlleft一张图片都没有 则pnlCenter 回原位 无需换图片数据
                    {
                        PanelPicMove(pnlLeft, pnlCenter, pnlRight, -1);
                    }
                    else
                    {
                        PanelPicMove(pnlCenter, pnlLeft, pnlRight, 1);
                        if (pnlHasPic(pnlRight))
                            rightPnlIndex -= pnlPicAmount;///如果右边pnl不为空...则右Pnl起始地址减少
                        if (leftPnlIndex  - pnlPicAmount < 0)
                        {
                            FillPnlPic(pnlRight, 0, 0);
                        }
                        else
                        {
                            leftPnlIndex -= pnlPicAmount;///如果左panel有照片填了 则左起始地址减少
                            FillPnlPic(pnlRight, leftPnlIndex, pnlPicAmount);
                        }
                    }
                }
            }
            else
            {
                //int NodeId;//摄像头id
                pnlPicBack(pnlLeft, pnlCenter, pnlRight); ///左中右Pnl归位
            }
            mouseDownX = 0;///鼠标按下坐标置为0
        }

        /// <summary>
        /// 填充三个pnl 的车辆照片
        /// </summary>
        /// <param name="pnlOnePicAmount"></param>
        /// <param name="pnlTwoPicAmount"></param>
        /// <param name="pnlThreePicAmount"></param>
        public void FillPic(int pnlOnePicAmount, int pnlTwoPicAmount, int pnlThreePicAmount)
        {
            int picIndexNow  = 0;
            int pnlPicAmount = 0;
            ParkingInquire.PublicClass.BackgroundPanel pnlPicPage = this.PnlPicPageTwo1;
            for (int i = 1; i < 4; i++)
            {
                if (i == 1)
                {
                    pnlPicAmount = pnlOnePicAmount;
                    pnlPicPage   = PnlPicPageTwo1;
                }
                else if (i == 2)
                {
                    pnlPicAmount = pnlTwoPicAmount;
                    pnlPicPage   = PnlPicPageTwo2;
                }
                else if (i == 3)
                {
                    pnlPicAmount = pnlThreePicAmount;
                    pnlPicPage   = PnlPicPageTwo3;
                }
                int j = 1;
                {
                    for (int k = pnlPicPage.Controls.Count - 1; k >= 0; k--)
                    {
                        PictureBox pictureBox = pnlPicPage.Controls[k] as PictureBox;
                        if (pictureBox != null)    ///当前为图片控件              
                        {
                            ///当前pnl加载的图片数量小于等于允许加载的最大图片数,并且照片下标号小于 照片总数
                            if (j <= pnlPicAmount && picIndexNow < carImage.Count)
                            {
                                pictureBox.Image = carImage[picIndexNow];
                                pictureBox.Tag   = carParkingId[picIndexNow];
                                picIndexNow++;
                                j++;
                            }
                            else
                            {
                                pictureBox.Image = null;
                                pictureBox.Tag   = null;
                            }
                        }
                    }

                    pnlPicPage.Update();
                }
            }
        }

        /// <summary>
        ///  车位照片Pnl 归位
        /// </summary>
        /// <param name="pnlleft">放置在左边的pnl</param>
        /// <param name="pnlCenter">放置在中间的Pnl</param>
        /// <param name="pnlRigth">放置在右边的pnl</param>
        public void pnlPicBack(Panel pnlLeft, Panel pnlCenter, Panel pnlRigth)
        {
            pnlCenter.Location = new Point(0, (PnlPageTwo.Height - pnlCenter.Height) / 2);
            pnlLeft.Location   = new Point(0 - pnlLeft.Width, (PnlPageTwo.Height - pnlCenter.Height) / 2);
            pnlRigth.Location  = new Point(pnlRigth.Width, (PnlPageTwo.Height - pnlCenter.Height) / 2);
        }

        /// <summary>
        /// 清除照片信息
        /// </summary>
        public void ClearPnlPic(ParkingInquire.PublicClass.BackgroundPanel panelControl)
        {
            foreach (Control control in panelControl.Controls)
            {
                PictureBox pictureBox = control as PictureBox;
                if (pictureBox != null)    ///当前为图片控件              
                {
                    pictureBox.Image = null;
                    pictureBox.Tag   = null;
                }
            }
        }

        /// <summary>
        /// 填充pnl 车辆照片
        /// </summary>
        /// <param name="panelControl">需要填充照片的panel</param>
        /// <param name="startIndex">开始下标</param>
        /// <param name="amount">需要填充的数量,0为该panel清空照片信息</param>
        public void FillPnlPic(Panel panelControl, int startIndex, int amount)
        {
            int FillAmount = 1;///已填充数量
            for (int picIndex = panelControl.Controls.Count - 1; picIndex >= 0; picIndex--)///这样循环就会从第一个PicBox开始填充图片
            {
                PictureBox pictureBox = panelControl.Controls[picIndex] as PictureBox;
                if (pictureBox != null)    ///当前为图片控件              
                {
                    ///当前pnl加载的图片数量小于等于允许加载的最大图片数,并且照片下标号小于 照片总数
                    if (FillAmount <= amount && startIndex < carImage.Count)
                    {
                        pictureBox.Image = carImage[startIndex];
                        pictureBox.Tag   = carParkingId[startIndex];
                        startIndex++;
                        FillAmount++;
                    }
                    else
                    {
                        pictureBox.Image = null;
                        pictureBox.Tag   = null;
                    }
                }
            }
        }

        /// <summary>
        ///  检查控件中的 PicBox是否有图片
        /// </summary>
        /// <param name="PicPanel"></param>
        /// <returns></returns>
        public bool pnlHasPic(Panel PicPanel)
        {
            bool result = false;
            foreach (Control control in PicPanel.Controls)
            {
                PictureBox pictureBox = control as PictureBox;
                if (pictureBox != null)    ///当前为图片控件              
                {
                    if (pictureBox.Tag != null)
                    {
                        result = true;
                        break;
                    }
                }
            }
            return result;
        }

        private void PnlPic_MouseDoubleClick(object sender, EventArgs e)
        {
            object sss  = ((PictureBox)sender).Tag;
            string name = ((PictureBox)sender).Name;
            string ssss = e.ToString();
        }
    }

原文地址:https://www.cnblogs.com/lonelyofsoul/p/winform_panel_picbox.html