I have a folder with a lot of files inside it. I want each of my files to display as a button. And when I click on the button, something will happen.
private void Form1_Load(object sender, EventArgs e)
{
int x = 10;
int y = 10;
string[] fileEntries = Directory.GetFiles(@"c:\lotsofDocs");
foreach (string fileName in fileEntries)
{
Button newbotton = new Button();
newbotton.AutoSize = true;
newbotton.Text = fileName;
panel1.Controls.Add(newbotton);
newbotton.Location = new Point(x, y);
x += 150;
if (x == 760)
{
y += 50;
x = 10;
}
}
As you can see, there is nothing crazy in the code. I have a panel on the form, and I set the auto scroll on the panel to true and auto size to false. This causes the form to support size and buttons (some of them anyway) to get visualization from the form, and I can scroll them down.
So far so good.
If I have 100 or 200 files, everything is fine, if I have 1932 files, it takes about 10 seconds to display all the buttons.
# custom control, , , , .
:
? Windows, .
Windows? - .