专门给你写了个示例: 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();
直到(0+前一张图的right+图片间距+当前宽>panel.clientsize.width的时候。y的值加上一个图片的高。一次类推吧。)
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();
}
}
}
{
if (ctl is PictureBox)
{
ctl.TabIndex;
ctl.Width = xxx;
ctl.Height = xxx;
ctl.Right = xxx;
ctl.Height = xxx;
}
}