private void anagrams_Click(object sender, EventArgs e)
{
input.Enabled = false;
Bag input_bag = new Bag(input.Text);
listView1.Items.Clear();
fileToolStripMenuItem.Enabled = false;
start_time = DateTime.Now;
elapsed_time.Text = "00:00:00";
timer1.Enabled = true;
ProgressBar.Value = 0;
Anagrams.anagrams(input_bag, dictionary, 0,
// bottom of main loop
delegate()
{
ProgressBar.PerformStep();
Application.DoEvents();
},
// done pruning
delegate(uint recursion_level, List<bag_and_anagrams> pruned_dict)
{
if (recursion_level == 0)
{
ProgressBar.Maximum = pruned_dict.Count;
Application.DoEvents();
}
},
// found a top-level anagram
delegate(strings words)
{
string display_me = "";
foreach (string s in words)
{
if (display_me.Length > 0)
display_me += " ";
display_me += s;
}
listView1.Items.Add(display_me);
listView1.EnsureVisible(listView1.Items.Count - 1);
toolStripStatusLabel1.Text = listView1.Items.Count.ToString() + " anagrams so far";
if (listView1.Items.Count % 1000 == 0)
{
Application.DoEvents();
}
});
timer1.Enabled = false;
toolStripStatusLabel1.Text = String.Format("Done. {0} anagrams",
listView1.Items.Count);
if (listView1.Items.Count > 0)
listView1.EnsureVisible(0);
input.Enabled = true;
input.Focus();
// the leading spaces work around a bug in the control: I
// want the text centered, but that doesn't work.
// Another workaround is for me to handle the
// DrawColumnHeader event myself, but I'm too lazy to do that.
listView1.Columns[0].Text = " Click to sort";
fileToolStripMenuItem.Enabled = true;
}