Purpose Provide an area for the user to drag and drop files to. |
Solution Implement the drag&drop functionality in a windows forms control and embed the control into the sap gui screen by using the callVB command. Example We will create an area with an image onto which the user can drop files. The filenames will then be available in a GuiXT variable for further processing. In this case, we just display all names in a new sap table control.
First of all we have to create a windows forms application. For many elements it is possible to activate the drag&drop functionality in three steps: The VB.NET Coding: Imports guinet Public Class Form1 Dim g As New guixt Private Sub Form1_Load(sender As Object, e As EventArgs) _ Handles MyBase.Load PictureBox1.AllowDrop = True End Sub Private Sub PictureBox1_DragEnter_1(sender As Object, e As DragEventArgs) _ Handles PictureBox1.DragEnter ' SET THE PROPER ACTION FOR FILE DROP.... ' BY USING THE FILEDROP METHOD TO COPY If e.Data.GetDataPresent(DataFormats.FileDrop) Then e.Effect = DragDropEffects.Link Else e.Effect = DragDropEffects.None End If End Sub Private Sub PictureBox1_DragDrop_1(sender As Object, e As DragEventArgs) _ Handles PictureBox1.DragDrop Try If e.Data.GetDataPresent("FileDrop", True) = True Then Dim Werte As String() = CType(e.Data.GetData("FileDrop"), Object) ' Dim fileNames As String = "" Dim i As Integer = 0 For Each f In Werte g.SetVariable("dragged_files." _ & (i + 1).ToString, Werte(i)) i += 1 Next ' Get name of InputScript Dim inputScript As String = "" inputScript = g.GetVariable("dragdrop_inputscript") ' Start InputScript ... g.Input("OK:/0,process=" & inputScript) End If Catch ex As Exception MsgBox(ex.Message) End Try End Sub Public Sub embed(ByVal w As Object, imagepath As String) Try If Not imagepath = "" Then PictureBox1.Image = Image.FromFile(imagepath) End If guixt.EmbedForm(Me, w) Catch ex As Exception MsgBox(ex.Message) End Try End Sub End Class Here is the GuiXT Script to embed the control and display the files in a new table:
// Create a container to embed our windows form control
// Define the script that will be run after a user dropped files
// Embed the control into our container
CallVB draganddrop.form1.embed w:="&V[r1]" _
endif
if not V[rows]
Set V[rows] "10"
endif
Table (0,162) (10,223) title="Dropped Files" name="droppedfiles" rows="&V[rows]"
Column "Filename" size=60 name="col1" Here is the InputScript that is processed after the user has dragged files onto the control:
Set V[i] 1
label nextRow
if V[dragged_files.&V[i]]
Set V[droppedfiles.cell.col1.&V[i]] "&V[dragged_files.&V[i]]"
goto nextRow
endif
Set V[rows] "&V[i]"
return
Result:
You can download all files for this example here: Here is video with further details about the project: Show video in full screen |
Components |