Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi All,

 

I just find a problem using drag & drag and ShowDialog problem in Visual Studio 2003.

 

In my form, I add DragDrop method:

 

private void Form11_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)

{

if(e.Data.GetDataPresent(DataFormats.FileDrop))

{

using(Form f1 = new Form10())

{

f1.ShowDialog(this);

}

}

}

 

Then I drag a file from Windows Explorer to the form and Form10 opens as expected. However, when I switch to Windows Explorer, I can't use the Windows Explorer as the focus is on Form10. If I close Form10, then the Windows Explorer can be reached and used again.

 

Can anyone help me to solve the above problem?

 

Many Thanks,

Vincent

  • Leaders
Posted

This is probably because the drag & drop source is waiting for the drag & drop operation to be completed. By performing a ShowDialog() in the event handler, which doesn't return control to the caller until the form is hidden, you are tying up the thread. Try something like this, which will show the modal dialog in the application's main UI thread:

// Invoke function that will show modal form on UI thread
private void MyControl_DragDrop(object sender, DragEventArgs e) {
   this.BeginInvoke(new SimpleVoid(ShowIt));
}

delegate void SimpleVoid(); // Delegate type to use with BeginInvoke

public void ShowIt() { // function to show modal form on UI thread
   using(Form1 newform = new Form1()) {
       newform.ShowDialog(this);
   }
}

[sIGPIC]e[/sIGPIC]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...