public partial class Form1 : Form
{
int maxwidth = 0;
public Form1()
{
InitializeComponent();
}
private void SearchAndDisplay()
{
Control ctrl = null; ;
int relative = 10;
DirectoryInfo di = new DirectoryInfo(@"C:\Users\kuthupar\Documents");
List<FileInfo> lFi = new List<FileInfo>();
lFi.AddRange(di.GetFiles("BET*"));
lFi = lFi.FindAll(delegate(FileInfo f) { return f.Extension.ToLower() == ".ppt" || f.Extension.ToLower() == ".pptx" || f.Extension.ToLower() == ".ppt"; });
int i = 1;
foreach (FileInfo fi in lFi)
{
TextBox txtbx = new TextBox();
txtbx.Name = "TextBox " + i.ToString();
try
{
Control[] ctrlArray = this.Controls.Find("TextBox " + (this.Controls.OfType<TextBox>().Count()).ToString(), false);
ctrl = ctrlArray[0];
}
catch { }
if (ctrl != null)
{
relative = ctrl.Bottom + ctrl.Height / 2;
}
txtbx.Top = relative;
txtbx.Text = fi.Name + ":" + fi.LastWriteTime.ToString();
maxwidth = maxwidth < txtbx.Text.Length * 6 + 10? txtbx.Text.Length*6+10: maxwidth;
txtbx.Width = maxwidth;
this.SuspendLayout();
this.Controls.Add(txtbx);
this.ResumeLayout();
i++;
}
}
private void AlignWidth()
{
foreach(Control ctrl in this.Controls.OfType<TextBox>())
{
ctrl.Width = maxwidth;
}
}
private void Form1_Load(object sender, EventArgs e)
{
SearchAndDisplay();
AlignWidth();
}
}