Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drag Drop events don't work on FastColoredTextBoxes #250

Open
voidZiAD opened this issue Aug 4, 2022 · 1 comment
Open

Drag Drop events don't work on FastColoredTextBoxes #250

voidZiAD opened this issue Aug 4, 2022 · 1 comment

Comments

@voidZiAD
Copy link

voidZiAD commented Aug 4, 2022

When using FastColoredTextbox, I'm not able to make the DragDrop or DragEnter or DragOver events work. Basically, when I put in some code inside the Events nothing changes, I've looked all over the internet to try making drag and drop work however it still does not.

Any solutions or any way this can be fixed for FastColoredTextbox?

@paradoxmind
Copy link

paradoxmind commented Dec 1, 2022

Greetings,

Hope this helps someone out.

  1. Make sure you are Not running your IDE as Admin (assuming Visual Studio here).
  2. Below is a working example. The FastColoredTextBox is named SqlCmdWindow.

private void SqlCmdWindow_DragOver(object sender, DragEventArgs e)
{
    // Check if the format of the data can be accepted
    // Only accept file drops from Explorer, etc.
    var ccx = StringComparison.InvariantCultureIgnoreCase;
    string[] files = (string[])e.Data.GetData(DataFormats.FileDrop, false);
    var filePath = files.FirstOrDefault();

    if (filePath != null && (filePath.EndsWith(".sql", ccx) || filePath.EndsWith(".txt", ccx)))
        e.Effect = DragDropEffects.Link;
    else
        e.Effect = DragDropEffects.None;

}

private void SqlCmdWindow_DragDrop(object sender, DragEventArgs e)
{
    // Extract the data from the DataObject-Container into a string list
    var ccx = StringComparison.InvariantCultureIgnoreCase;
    string[] files = (string[])e.Data.GetData(DataFormats.FileDrop, false);
    var filePath = files.FirstOrDefault();

    if (filePath != null && (filePath.EndsWith(".sql", ccx) || filePath.EndsWith(".txt", ccx)))
    {
        TitleMsg.Text = filePath;                
        var fileText = File.ReadAllText(filePath);

        // Add file text into FastColoredTextBox control:
        SqlCmdWindow.Text = fileText;
    }
}

Hope this helps : )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants