orglce
orglce

Reputation: 543

Set drag & drop to multiple textboxes

I have 9 textboxes in my application. I would like to set drag & drop effect to every textbox in my app. I have written drag & drop effect with two events. DragEnter and DragDrop. But I have written it for every textbox separately. How can I set it to every textbox with just one event without have to write it for every textbox separately. here is my drag and drop effect for one textbox:

private void SystemTextBox_DragEnter(object sender, DragEventArgs e)
    {
        if (e.Data.GetDataPresent(DataFormats.FileDrop))
            e.Effect = DragDropEffects.Copy;
    }

    private void SystemTextBox_DragDrop(object sender, DragEventArgs e)
    {
        string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
        if (files != null && files.Length != 0)
        {
            SystemTextBox.Text = files[0];
        }
    }

Upvotes: 0

Views: 468

Answers (1)

TaW
TaW

Reputation: 54453

First make all TextBoxes point to the same DD events. Then change this

SystemTextBox.Text = files[0];

to

((TextBox)sender).Text = files[0];

You may want to change the names to something more genric like "allTextBoxes_DragDrop" or so..

Upvotes: 1

Related Questions