Panel1中的有100个Picturebox,当我把Panel1的尺寸改变时(例如:panel1.Dock = DockStyle.None改为panel1.Dock = DockStyle.Fill),如何让Panel中的100个Picturebox控件重新排列啊?提供思路也行,请各位高手多多帮助我!

解决方案 »

  1.   

    cjnet(孤星剑),你好,图片数组的定义是否如下:Image img[] = new Image[100];可否给一个例子,谢谢!
      

  2.   

    帮你up,不过一个panel里头有那么多的picturebox控件,在切换窗体的时候会不会闪哪?
      

  3.   

    wuyazhe(我的宝贝叫阿刺),您好,可否贴一些代码让我学习学习,谢谢!另:panel在切换窗体的时候是会闪的,可是我也没有没办法,这个功能(Panel1的尺寸改变时Picturebox控件重新排列)领导说一定要有,我该咋办啊!
      

  4.   

    你想怎么排就怎么计算被~ ,第一张图,就(0,0),第二张就(0+前一张图的right+图片间距,0)...
    直到(0+前一张图的right+图片间距+当前宽>panel.clientsize.width的时候。y的值加上一个图片的高。一次类推吧。)
      

  5.   

    在panel里套表格来控制位置行不
      

  6.   

    专门给你写了个示例:
    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;namespace ToolTipTest
    {
    /// <summary>
    /// Form1 的摘要说明。
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
    private System.Windows.Forms.Panel panel1;
    private System.ComponentModel.IContainer components; public Form1()
    {
    //
    // Windows 窗体设计器支持所必需的
    //
    InitializeComponent();

    //
    // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
    //
    } /// <summary>
    /// 清理所有正在使用的资源。
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if (components != null) 
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    } #region Windows 窗体设计器生成的代码
    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
    this.panel1 = new System.Windows.Forms.Panel();
    this.SuspendLayout();
    // 
    // panel1
    // 
    this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
    this.panel1.Location = new System.Drawing.Point(0, 0);
    this.panel1.Name = "panel1";
    this.panel1.Size = new System.Drawing.Size(736, 273);
    this.panel1.TabIndex = 0;
    this.panel1.SizeChanged += new System.EventHandler(this.panel1_SizeChanged);
    // 
    // Form1
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
    this.ClientSize = new System.Drawing.Size(736, 273);
    this.Controls.Add(this.panel1);
    this.Name = "Form1";
    this.Text = "Form1";
    this.Load += new System.EventHandler(this.Form1_Load);
    this.ResumeLayout(false); }
    #endregion /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    [STAThread]
    static void Main() 
    {
    Application.Run(new Form1());
    } private  PictureBox[] p =new PictureBox[100];
    private void Form1_Load(object sender, System.EventArgs e)
    {

    for(int i=0;i<p.Length;i++)
    {
    p[i]=new PictureBox();
    p[i].BorderStyle=BorderStyle.FixedSingle;
    this.panel1.Controls.Add(p[i]);
    }

    SetControlsLocation();
    } private void panel1_SizeChanged(object sender, System.EventArgs e)
    {
    SetControlsLocation();
    }
    private void SetControlsLocation()
    {
      this.panel1.Hide();
      int ControlWidth =this.panel1.Width/10;
      int ControlHeight =this.panel1.Height/10;
      int x =0;
      int y=0;
    foreach (Control tmpCtr in this.panel1.Controls)
    {
    tmpCtr.Width =ControlWidth;
    tmpCtr.Height =ControlHeight;
    if(this.panel1.Width-x<ControlWidth)
    {
    x=0;
    y+=ControlHeight;
    }
    tmpCtr.Left =x;
    tmpCtr.Top=y;
    tmpCtr.BringToFront();
    x+=ControlWidth;

    }
      this.panel1.Show();
    }
    }
    }
      

  7.   

    foreach(Control ctl in this.panel1.Controls)
    {
    if (ctl is PictureBox)
    {
    ctl.TabIndex;
    ctl.Width = xxx;
    ctl.Height = xxx;
    ctl.Right = xxx;
    ctl.Height = xxx;
    }
    }
      

  8.   

    谢谢各位热心人,特别感谢 SqlDataAdapter(咸蛋超人) ,我试一下。生活第一,工作第二,呵呵……