据说是可以挂起,然后ResumeLayout()结束挂起。using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WindowsApplication1
{
public partial class Form1 : Form
{
private string path = "../../QQ截图未命名.png";
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
TJ();
}
private void TJ()
{
NewMethod();
//this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 40F));
} private void NewMethod()
{
this.tableLayoutPanel1.SuspendLayout();
this.tableLayoutPanel1.Controls.Clear();
this.tableLayoutPanel1.RowCount = 0;
string[] strs = new string[] { "1", "2", "1", "2", "../../QQ截图未命名.png", "2", "1", "2" };
string[] strs1 = new string[] { "1", "2", "1", "2", "1", "../../QQ截图未命名.png", "1", "2" };
string[] strs2 = new string[] { "1", "2", "../../QQ截图未命名.png", "2", "1", "2", "1", "2" };
string[] strs3 = new string[] { "1", "2", "1", "2", "../../QQ截图未命名.png", "2", "1", "2" };
this.tableLayoutPanel1.ColumnCount = 1;
List<string[]> list = new List<string[]>();
list.Add(strs);
list.Add(strs1);
list.Add(strs2);
list.Add(strs3);
foreach (string[] strss in list)
{
this.tableLayoutPanel1.RowCount += 1;
for (int i = 0; i < strs.Length; i++)
{
if (this.tableLayoutPanel1.ColumnCount < strs.Length)
{
this.tableLayoutPanel1.ColumnCount += 1;
//this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 20F));
}
PictureBox p = new PictureBox();
if (strss[i] == path)
{
p.Image = Image.FromFile(path);
}
this.tableLayoutPanel1.Controls.Add(p);
}
}
this.tableLayoutPanel1.ResumeLayout();
} private void button1_Click(object sender, EventArgs e)
{
this.tableLayoutPanel1.SuspendLayout();
this.tableLayoutPanel1.Controls.Clear();
this.tableLayoutPanel1.RowCount = 0;
string[] strs = new string[] { "1", "2", "1", "2", "../../QQ截图未命名.png", "2", "1", "2" };
string[] strs1 = new string[] { "1", "2", "1", "2", "1", "../../QQ截图未命名.png", "1", "2" };
string[] strs2 = new string[] { "1", "2", "../../QQ截图未命名.png", "2", "1", "2", "1", "2" };
string[] strs3 = new string[] { "1", "2", "1", "2", "../../QQ截图未命名.png", "2", "1", "2" }; this.tableLayoutPanel1.ColumnCount = 1;
List<string[]> list = new List<string[]>();
list.Add(strs1);
list.Add(strs2);
list.Add(strs2);
list.Add(strs3);
foreach (string[] strss in list)
{
this.tableLayoutPanel1.RowCount += 1;
for (int i = 0; i < strs.Length; i++)
{
if (this.tableLayoutPanel1.ColumnCount < strs.Length)
{
this.tableLayoutPanel1.ColumnCount += 1;
}
if (strss[i] == path)
{
PictureBox p = new PictureBox();
p.Image = Image.FromFile(path);
this.tableLayoutPanel1.Controls.Add(p);
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 20F));
}
}
}
this.ResumeLayout();
} private void button2_Click(object sender, EventArgs e)
{
NewMethod();
}
}
}加了不加这两个方法可以出来4个图,加了之后,就出来了一个图。不知道为什么。还有呀,其实加这个方法为了解决NEW了这么多控件,会出现闪烁的问题,有没有别的方法呢?
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WindowsApplication1
{
public partial class Form1 : Form
{
private string path = "../../QQ截图未命名.png";
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
TJ();
}
private void TJ()
{
NewMethod();
//this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 40F));
} private void NewMethod()
{
this.tableLayoutPanel1.SuspendLayout();
this.tableLayoutPanel1.Controls.Clear();
this.tableLayoutPanel1.RowCount = 0;
string[] strs = new string[] { "1", "2", "1", "2", "../../QQ截图未命名.png", "2", "1", "2" };
string[] strs1 = new string[] { "1", "2", "1", "2", "1", "../../QQ截图未命名.png", "1", "2" };
string[] strs2 = new string[] { "1", "2", "../../QQ截图未命名.png", "2", "1", "2", "1", "2" };
string[] strs3 = new string[] { "1", "2", "1", "2", "../../QQ截图未命名.png", "2", "1", "2" };
this.tableLayoutPanel1.ColumnCount = 1;
List<string[]> list = new List<string[]>();
list.Add(strs);
list.Add(strs1);
list.Add(strs2);
list.Add(strs3);
foreach (string[] strss in list)
{
this.tableLayoutPanel1.RowCount += 1;
for (int i = 0; i < strs.Length; i++)
{
if (this.tableLayoutPanel1.ColumnCount < strs.Length)
{
this.tableLayoutPanel1.ColumnCount += 1;
//this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 20F));
}
PictureBox p = new PictureBox();
if (strss[i] == path)
{
p.Image = Image.FromFile(path);
}
this.tableLayoutPanel1.Controls.Add(p);
}
}
this.tableLayoutPanel1.ResumeLayout();
} private void button1_Click(object sender, EventArgs e)
{
this.tableLayoutPanel1.SuspendLayout();
this.tableLayoutPanel1.Controls.Clear();
this.tableLayoutPanel1.RowCount = 0;
string[] strs = new string[] { "1", "2", "1", "2", "../../QQ截图未命名.png", "2", "1", "2" };
string[] strs1 = new string[] { "1", "2", "1", "2", "1", "../../QQ截图未命名.png", "1", "2" };
string[] strs2 = new string[] { "1", "2", "../../QQ截图未命名.png", "2", "1", "2", "1", "2" };
string[] strs3 = new string[] { "1", "2", "1", "2", "../../QQ截图未命名.png", "2", "1", "2" }; this.tableLayoutPanel1.ColumnCount = 1;
List<string[]> list = new List<string[]>();
list.Add(strs1);
list.Add(strs2);
list.Add(strs2);
list.Add(strs3);
foreach (string[] strss in list)
{
this.tableLayoutPanel1.RowCount += 1;
for (int i = 0; i < strs.Length; i++)
{
if (this.tableLayoutPanel1.ColumnCount < strs.Length)
{
this.tableLayoutPanel1.ColumnCount += 1;
}
if (strss[i] == path)
{
PictureBox p = new PictureBox();
p.Image = Image.FromFile(path);
this.tableLayoutPanel1.Controls.Add(p);
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 20F));
}
}
}
this.ResumeLayout();
} private void button2_Click(object sender, EventArgs e)
{
NewMethod();
}
}
}加了不加这两个方法可以出来4个图,加了之后,就出来了一个图。不知道为什么。还有呀,其实加这个方法为了解决NEW了这么多控件,会出现闪烁的问题,有没有别的方法呢?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货