private static int GroupId = 1; int Column = 4; int Row = 1;
private static int x1 = 0; int x2 = 120; int x3 = 140;
private static int y1 = 0; int y2 = 0; int y3 = 0; public Form3()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
PictureBox p = new PictureBox();
p.BorderStyle = BorderStyle.FixedSingle; p.Image = objImage; //Image.FromFile(@"D:\wubw\AutoCity.UploadImages\AutoCity.UploadImages\bin\Debug\0.jpg");
p.Name = "pbx" + GroupId;
this.panel1.Controls.Add(p); TextBox t = new TextBox();
t.Name = "tb" + GroupId;
panel1.Controls.Add(t); Button b = new Button();
b.Name = "bt" + GroupId;
b.Text = "浏览";
b.MouseDown += new MouseEventHandler(this.ButtonArray_OnClick);
panel1.Controls.Add(b); Button del = new Button();
del.Name = "del" + GroupId;
del.Text = "删除";
del.MouseDown += new MouseEventHandler(this.ButtonArraydel_OnClick);
panel1.Controls.Add(del);
SetControlsLocation();
GroupId++;
} private bool ThumbnailCallBack()
{
return false;
} private void SetControlsLocation()
{
this.panel1.Hide(); int btWidth = 45; int pbxWidth = 150; int w = 0; //int p = GroupId % Column;
//if (GroupId % Column == 0)
//{
// x1 += 180;
// y1 = 0;
//} foreach (Control tmpCtr in panel1.Controls)
{
w++;
if (tmpCtr.Text == "添加新图片")
{
continue;
} if (tmpCtr.Name == "pbx" + GroupId)
{
tmpCtr.Top = x1;
tmpCtr.Left = y1;
tmpCtr.Width = pbxWidth;
tmpCtr.Height = 120;
}
if (tmpCtr.Name == "tb" + GroupId)
{
tmpCtr.Top = x2;
tmpCtr.Left = y2;
tmpCtr.Width = pbxWidth;
} if (tmpCtr.Name == "bt" + GroupId)
{
tmpCtr.Top = x3;
tmpCtr.Left = y3;
tmpCtr.Height = 25;
tmpCtr.Width = btWidth;
} if (tmpCtr.Name == "del" + GroupId)
{
tmpCtr.Top = x3;
tmpCtr.Left = y3+btWidth;
tmpCtr.Height = 25;
tmpCtr.Width = btWidth;
} tmpCtr.BringToFront();
}
y1 += pbxWidth + 5;
y2 += pbxWidth + 5;
y3 += pbxWidth + 5;
button1.Left = y1 + 50;
button1.Top = x1; if ((GroupId % Column) == 0 && GroupId/Column == Row)
{
x1 += 180; x2 += 180; x3 += 180;
y1 = 0; y2 = 0; y3 = 0;
Row++;
} //MessageBox.Show(x1.ToString());
this.panel1.Show();
}
排列的时候出现错误,谁帮我看看,先谢谢了.
研究了下上面的代码, 如果我删除了中间的某一张图片,图片没了,但是位置却空在哪里,这样整个pannel里控件又要怎么排序去将那个删除了图片的位置补上了..