Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 22 additions & 4 deletions Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,22 @@ private void Form1_FormClosing(object sender, FormClosingEventArgs e)
Application.Exit();
}
}


int WordCount(string text)
{
int count = 0;
for (int i = 0; i < text.Length; ++i)
{
if (!char.IsWhiteSpace(text[i]))
{
++count;
while (++i < text.Length && !char.IsWhiteSpace(text[i]))
;
}
}
return count;
}

private void richTextBox1_TextChanged(object sender, EventArgs e)
{
if (TextHasChanged == false)
Expand All @@ -109,14 +124,12 @@ private void richTextBox1_TextChanged(object sender, EventArgs e)
TextHasChanged = true;
}

int Count = System.Text.RegularExpressions.Regex.Matches(richTextBox1.Text, @"[\S]+").Count;
int Count = WordCount(richTextBox1.Text);
wordCountToolStripStatusLabel.Text = Count.ToString() + " word";
if (Count > 1)
{
wordCountToolStripStatusLabel.Text += "s";
}

ChangePositionToolStripStatusLabel();
}

private void ExitToolStripMenuItem_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -711,5 +724,10 @@ private void replaceAllToolStripMenuItem_Click(object sender, EventArgs e)
else
MessageBox.Show("Cannot find '" + FindTextString + "'", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
}

private void richTextBox1_SelectionChanged(object sender, EventArgs e)
{
ChangePositionToolStripStatusLabel();
}
}
}