There are several cases which you haven't considered where you code will currently crash. Start by fixing those:
private void fastColoredTextBox1_DragOver(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.None;
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
if (files.Length == 1 && string.Equals(Path.GetExtension(files[0]), ".txt", StringComparison.OrdinalIgnoreCase))
{
e.Effect = DragDropEffects.All;
}
}
}
private void fastColoredTextBox1_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
if (files.Length == 1 && string.Equals(Path.GetExtension(files[0]), ".txt", StringComparison.OrdinalIgnoreCase))
{
fastColoredTextBox1.Text = File.ReadAllText(files[0]);
}
}
}
If it still doesn't work, then you'll need to log a bug on the GitHub project:
GitHub - PavelTorgashov/FastColoredTextBox: Fast Colored TextBox for Syntax Highlighting. The text editor component for .NET.[
^]
Or post a question in the forum at the bottom of the CodeProject article:
Fast Colored TextBox for Syntax Highlighting[
^]