準備
(なし)
デザイン
- フォーム (Form1) にボタン (button1) を配置します。
サンプルコード (C#)
namespace WinFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
this.SuspendLayout();
for (int i = 0; i < 900; i++)
{
var btn = new Button()
{
Location = new Point(0, 0),
Size = new Size(100, 100)
};
this.Controls.Add(btn);
}
this.ResumeLayout();
listBox1.Items.Add("ボタン作成完了。");
}
}
}
解説
フォーム (Form1) にコントロールを大量に配置する場合は、配置が終了するまで、コントロールの描画を一時停止します。
結果
動作確認環境
Visual Studio 2022 Professional (.NET8 C#12)
ログ
初版:2016.05.07 Visual Studio 2015 Professional (C# 6.0)
