We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

How do I make the HTMLUI control to load html documents by dragging and dropping them on the control ?

 

HTMLUI control is made to support various events related to the drag drop operation.

The Allowdrop property of the HTMLUI control should be made to true, this helps in supporting the drag drop operation on the control.

The DataFormats and the DragDropEffects should be decided to determine the action of the DragDrop event. These formats and effects can be got or set with the help of the DragEvent arguments.

During DragDrop, the file name of the document along with the location is collected and when the mouse button is released, the specified document is loaded from the mentioned location through the LoadHTML method of the HTMLUI control.

C#

//To support drag events to the control

this.htmluiControl1.AllowDrop = true;

//DragDrop and DragEnter events declaration

this.htmluiControl1.DragDrop += new System.Windows.Forms.DragEventHandler(this.htmluiControl1_DragDrop);

this.htmluiControl1.DragEnter += new System.Windows.Forms.DragEventHandler(this.htmluiControl1_DragEnter);

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

{

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

//Specifying the drop effect

e.Effect = DragDropEffects.All;

else

e.Effect = DragDropEffects.None;

}

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

{

//Specifying the drop format and collecting the file name

string[] files = (string[])e.Data.GetData("FileDrop", false);

foreach (string fileName in files)

{

//Loading the specified file in to the HTMLUI control

this.htmluiControl1.LoadHTML(fileName);

}

}

VB

'To support drag events to the control

Private Me.htmluiControl1.AllowDrop = True

'DragDrop and DragEnter events declaration

Private Me.htmluiControl1.DragDrop += New System.Windows.Forms.DragEventHandler(Me.htmluiControl1_DragDrop)

Private Me.htmluiControl1.DragEnter += New System.Windows.Forms.DragEventHandler(Me.htmluiControl1_DragEnter)

Private Sub htmluiControl1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs)

If e.Data.GetDataPresent (DataFormats.FileDrop) Then

'Specifying the drop effect

e.Effect = DragDropEffects.All

Else

e.Effect = DragDropEffects.None

End If

End Sub

Private Sub htmluiControl1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs)

'Specifying the drop format and collecting the file name

Dim files As String() = CType(e.Data.GetData("FileDrop", False), String())

For Each fileName As String In files

'Loading the specified file in to the HTMLUI control

Me.htmluiControl1.LoadHTML(fileName)

Next fileName

End Sub

Article ID: Published Date: Last Revised Date: Platform: Control:
815 04/30/2011 07/10/2014 Windows Forms HTMLUIControl
Tags:
Did you find this information helpful?
Add Comment
You must log in to leave a comment

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.