Imports AxSftTreeLib70 Imports SftTreeLib70 Imports Softelvdm.OLEConvert Public Class Form1 Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Public WithEvents Picture2 As System.Windows.Forms.PictureBox Public WithEvents Text1 As System.Windows.Forms.TextBox Public WithEvents Command1 As System.Windows.Forms.Button Public WithEvents Picture1 As System.Windows.Forms.PictureBox Public WithEvents Label5 As System.Windows.Forms.Label Public WithEvents DropTarget As System.Windows.Forms.Label Public WithEvents DropTargetPic As System.Windows.Forms.PictureBox Public WithEvents Label4 As System.Windows.Forms.Label Public WithEvents Label3 As System.Windows.Forms.Label Public WithEvents Label2 As System.Windows.Forms.Label Public WithEvents Label1 As System.Windows.Forms.Label Friend WithEvents AxSftTree1 As AxSftTreeLib70.AxSftTree Friend WithEvents SftHelperComponent1 As Softelvdm.OCXHelper.SftHelperComponent <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() Me.components = New System.ComponentModel.Container() Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1)) Me.Picture2 = New System.Windows.Forms.PictureBox() Me.Text1 = New System.Windows.Forms.TextBox() Me.Command1 = New System.Windows.Forms.Button() Me.Picture1 = New System.Windows.Forms.PictureBox() Me.Label5 = New System.Windows.Forms.Label() Me.DropTarget = New System.Windows.Forms.Label() Me.DropTargetPic = New System.Windows.Forms.PictureBox() Me.Label4 = New System.Windows.Forms.Label() Me.Label3 = New System.Windows.Forms.Label() Me.Label2 = New System.Windows.Forms.Label() Me.Label1 = New System.Windows.Forms.Label() Me.AxSftTree1 = New AxSftTreeLib70.AxSftTree() Me.SftHelperComponent1 = New Softelvdm.OCXHelper.SftHelperComponent(Me.components) CType(Me.AxSftTree1, System.ComponentModel.ISupportInitialize).BeginInit() Me.SuspendLayout() ' 'Picture2 ' Me.Picture2.BackColor = System.Drawing.SystemColors.Control Me.Picture2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D Me.Picture2.Cursor = System.Windows.Forms.Cursors.Default Me.Picture2.Font = New System.Drawing.Font("Arial", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Picture2.ForeColor = System.Drawing.SystemColors.ControlText Me.Picture2.Image = CType(resources.GetObject("Picture2.Image"), System.Drawing.Bitmap) Me.Picture2.Location = New System.Drawing.Point(302, 163) Me.Picture2.Name = "Picture2" Me.Picture2.RightToLeft = System.Windows.Forms.RightToLeft.No Me.Picture2.Size = New System.Drawing.Size(25, 17) Me.Picture2.TabIndex = 30 Me.Picture2.TabStop= False ' 'Text1 ' Me.Text1.AcceptsReturn = True Me.Text1.AutoSize= False Me.Text1.BackColor = System.Drawing.SystemColors.Window Me.Text1.Cursor = System.Windows.Forms.Cursors.IBeam Me.Text1.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Text1.ForeColor = System.Drawing.SystemColors.WindowText Me.Text1.Location = New System.Drawing.Point(336, 163) Me.Text1.MaxLength = 0 Me.Text1.Name = "Text1" Me.Text1.RightToLeft = System.Windows.Forms.RightToLeft.No Me.Text1.Size = New System.Drawing.Size(96, 19) Me.Text1.TabIndex = 28 Me.Text1.Text = "Text1" ' 'Command1 ' Me.Command1.BackColor = System.Drawing.SystemColors.Control Me.Command1.Cursor = System.Windows.Forms.Cursors.Default Me.Command1.DialogResult = System.Windows.Forms.DialogResult.Cancel Me.Command1.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Command1.ForeColor = System.Drawing.SystemColors.ControlText Me.Command1.Location = New System.Drawing.Point(366, 6) Me.Command1.Name = "Command1" Me.Command1.RightToLeft = System.Windows.Forms.RightToLeft.No Me.Command1.Size = New System.Drawing.Size(73, 27) Me.Command1.TabIndex = 25 Me.Command1.Text = "Close" ' 'Picture1 ' Me.Picture1.BackColor = System.Drawing.SystemColors.Control Me.Picture1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D Me.Picture1.Cursor = System.Windows.Forms.Cursors.Default Me.Picture1.Font = New System.Drawing.Font("Arial", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Picture1.ForeColor = System.Drawing.SystemColors.ControlText Me.Picture1.Image = CType(resources.GetObject("Picture1.Image"), System.Drawing.Bitmap) Me.Picture1.Location = New System.Drawing.Point(270, 163) Me.Picture1.Name = "Picture1" Me.Picture1.RightToLeft = System.Windows.Forms.RightToLeft.No Me.Picture1.Size = New System.Drawing.Size(25, 17) Me.Picture1.TabIndex = 27 Me.Picture1.TabStop = False ' 'Label5 ' Me.Label5.BackColor = System.Drawing.SystemColors.Control Me.Label5.Cursor = System.Windows.Forms.Cursors.Default Me.Label5.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label5.ForeColor = System.Drawing.SystemColors.ControlText Me.Label5.Location = New System.Drawing.Point(6, 339) Me.Label5.Name = "Label5" Me.Label5.RightToLeft = System.Windows.Forms.RightToLeft.No Me.Label5.Size = New System.Drawing.Size(433, 49) Me.Label5.TabIndex = 34 Me.Label5.Text = "Drag items from the tree control to the drop target shown above. Or drag the ima" & _ "ges or text from the drag sources above. You can also use Windows Explorer as a" & _ " drag source or simply drag && drop within the tree control." ' 'DropTarget ' Me.DropTarget.AllowDrop = True Me.DropTarget.BackColor = System.Drawing.SystemColors.Control Me.DropTarget.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D Me.DropTarget.Cursor = System.Windows.Forms.Cursors.Default Me.DropTarget.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.DropTarget.ForeColor = System.Drawing.SystemColors.ControlText Me.DropTarget.Location = New System.Drawing.Point(294, 299) Me.DropTarget.Name = "DropTarget" Me.DropTarget.RightToLeft = System.Windows.Forms.RightToLeft.No Me.DropTarget.Size = New System.Drawing.Size(145, 25) Me.DropTarget.TabIndex = 33 ' 'DropTargetPic ' Me.DropTargetPic.Cursor = System.Windows.Forms.Cursors.Default Me.DropTargetPic.Location = New System.Drawing.Point(270, 299) Me.DropTargetPic.Name = "DropTargetPic" Me.DropTargetPic.Size = New System.Drawing.Size(25, 25) Me.DropTargetPic.TabIndex = 35 Me.DropTargetPic.TabStop = False ' 'Label4 ' Me.Label4.BackColor = System.Drawing.SystemColors.Control Me.Label4.Cursor = System.Windows.Forms.Cursors.Default Me.Label4.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label4.ForeColor = System.Drawing.SystemColors.ControlText Me.Label4.Location = New System.Drawing.Point(270, 238) Me.Label4.Name = "Label4" Me.Label4.RightToLeft = System.Windows.Forms.RightToLeft.No Me.Label4.Size = New System.Drawing.Size(161, 56) Me.Label4.TabIndex = 32 Me.Label4.Text = "Drag items from the tree control to the drop target below. In this example, only" & _ " one item is shown." ' 'Label3 ' Me.Label3.BackColor = System.Drawing.SystemColors.Control Me.Label3.Cursor = System.Windows.Forms.Cursors.Default Me.Label3.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label3.ForeColor = System.Drawing.SystemColors.ControlText Me.Label3.Location = New System.Drawing.Point(270, 211) Me.Label3.Name = "Label3" Me.Label3.RightToLeft = System.Windows.Forms.RightToLeft.No Me.Label3.Size = New System.Drawing.Size(161, 25) Me.Label3.TabIndex = 31 Me.Label3.Text = "Drop Target" ' 'Label2 ' Me.Label2.BackColor = System.Drawing.SystemColors.Control Me.Label2.Cursor = System.Windows.Forms.Cursors.Default Me.Label2.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label2.ForeColor = System.Drawing.SystemColors.ControlText Me.Label2.Location = New System.Drawing.Point(270, 51) Me.Label2.Name = "Label2" Me.Label2.RightToLeft = System.Windows.Forms.RightToLeft.No Me.Label2.Size = New System.Drawing.Size(161, 25) Me.Label2.TabIndex = 29 Me.Label2.Text = "Drag Sources" ' 'Label1 ' Me.Label1.BackColor = System.Drawing.SystemColors.Control Me.Label1.Cursor = System.Windows.Forms.Cursors.Default Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label1.ForeColor = System.Drawing.SystemColors.ControlText Me.Label1.Location = New System.Drawing.Point(270, 83) Me.Label1.Name = "Label1" Me.Label1.RightToLeft = System.Windows.Forms.RightToLeft.No Me.Label1.Size = New System.Drawing.Size(161, 73) Me.Label1.TabIndex = 26 Me.Label1.Text = "Drag the images or text shown below to the tree control or use Windows Explorer t" & _ "o drag one or more file names and drop them on the tree control." ' 'AxSftTree1 ' Me.AxSftTree1.Location = New System.Drawing.Point(8, 6) Me.AxSftTree1.Name = "AxSftTree1" Me.AxSftTree1.OcxState = CType(resources.GetObject("AxSftTree1.OcxState"), System.Windows.Forms.AxHost.State) Me.AxSftTree1.Size = New System.Drawing.Size(257, 329) Me.AxSftTree1.TabIndex = 24 ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.CancelButton = Me.Command1 Me.ClientSize = New System.Drawing.Size(445, 395) Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Picture2, Me.Text1, Me.Command1, Me.Picture1, Me.Label5, Me.DropTarget, Me.DropTargetPic, Me.Label4, Me.Label3, Me.Label2, Me.Label1, Me.AxSftTree1}) Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog Me.Name = "Form1" Me.Text = "Softel vdm, Inc. - DragDrop Sample" CType(Me.AxSftTree1, System.ComponentModel.ISupportInitialize).EndInit() Me.ResumeLayout(False) End Sub #End Region '--locate-marker-- Private Sub Command1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Command1.Click Application.Exit() End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load DropTargetPic.AllowDrop = True Dim i As Integer AxSftTree1.Items.Add("Item 0") i = AxSftTree1.Items.Add("Item 1") AxSftTree1.get_Item(i).Level = 1 i = AxSftTree1.Items.Add("Item 2") AxSftTree1.get_Item(i).Level = 2 i = AxSftTree1.Items.Add("Item 3") AxSftTree1.get_Item(i).Level = 1 End Sub Private Sub AxSftTree1_DragStarting(ByVal sender As Object, ByVal e As AxSftTreeLib70._DSftTreeEvents_DragStartingEvent) Handles AxSftTree1.DragStarting AxSftTree1.CancelMode() ' .NET controls drag&drop, so tree control needs to cancel ' This section demonstrates drag (&drop) using the .NET DoDragDrop method ' THIS CODE IS ONLY USED IF DRAGMETHOD IS SET TO ( 1 - Manual ) or SftTreeDragMethodConstants.dragSftTreeManual Dim curr As Integer curr = AxSftTree1.Items.Current ' cell text Dim Data As System.Windows.Forms.DataObject Data = New System.Windows.Forms.DataObject() Data.SetData(DataFormats.Text, AxSftTree1.get_Cell(curr, 0).Text) ' item picture Dim img As SftPictureObject If AxSftTree1.get_Item(curr).Image.Type = SftPictureTypeConstants.sftTypeIDispatch Then img = AxSftTree1.get_Item(curr).Image Else If AxSftTree1.get_Item(curr).Expanded Then img = AxSftTree1.Items.ItemImageExpanded ElseIf AxSftTree1.get_Item(curr).DependentAllCount > 0 Then img = AxSftTree1.Items.ItemImageExpandable Else img = AxSftTree1.Items.ItemImageLeaf End If End If Dim sendingImage As Image = OLECvt.ToImage(img.Picture) Data.SetData(DataFormats.Bitmap, True, sendingImage) DoDragDrop(Data, DragDropEffects.Copy) End Sub Private Sub AxSftTree1_OLEStartDrag(ByVal sender As Object, ByVal e As AxSftTreeLib70._DSftTreeEvents_OLEStartDragEvent) Handles AxSftTree1.OLEStartDrag ' This section demonstrates drag&drop) using OLE mechanisms built into this control ' THIS CODE IS ONLY USED IF DRAGMETHOD IS SET TO ( 3 - OLEDrag ) or SftTreeDragMethodConstants.dragSftTreeOLE Dim curr As Integer curr = AxSftTree1.Items.Current ' cell text e.data.SetData(AxSftTree1.get_Cell(curr, 0).Text, SftOLEClipboardConstants.sftCFText) ' item picture Dim img As SftPictureObject If AxSftTree1.get_Item(curr).Image.Type = SftPictureTypeConstants.sftTypeIDispatch Then img = AxSftTree1.get_Item(curr).Image Else If AxSftTree1.get_Item(curr).Expanded Then img = AxSftTree1.Items.ItemImageExpanded ElseIf AxSftTree1.get_Item(curr).DependentAllCount > 0 Then img = AxSftTree1.Items.ItemImageExpandable Else img = AxSftTree1.Items.ItemImageLeaf End If End If e.data.SetData(img.Picture, SftOLEClipboardConstants.sftCFDIB) e.data.SetData(img.Picture, SftOLEClipboardConstants.sftCFBitmap) e.allowedEffects = 3 End Sub Private Sub DropTarget_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles DropTarget.DragEnter If e.Data.GetDataPresent(DataFormats.Text, True) Or e.Data.GetDataPresent(DataFormats.Bitmap, True) Then e.Effect = DragDropEffects.Copy Else e.Effect = DragDropEffects.None End If End Sub Private Sub DropTarget_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles DropTarget.DragDrop Dim arrayOfFormats As [String]() = e.Data.GetFormats(True) ' informational If e.Data.GetDataPresent(DataFormats.Text, True) Then DropTarget.Text = e.Data.GetData(DataFormats.Text, True) End If If e.Data.GetDataPresent(DataFormats.Bitmap, True) Then DropTargetPic.Image = e.Data.GetData(DataFormats.Bitmap, True) End If End Sub Private Sub DropTargetPic_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles DropTargetPic.DragEnter If e.Data.GetDataPresent(DataFormats.Bitmap, True) Then e.Effect = DragDropEffects.Copy Else e.Effect = DragDropEffects.None End If End Sub Private Sub DropTargetPic_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles DropTargetPic.DragDrop Dim arrayOfFormats As [String]() = e.Data.GetFormats(True) ' informational If e.Data.GetDataPresent(DataFormats.Bitmap, True) Then Dim O As Object = e.Data.GetData(DataFormats.Bitmap, True) DropTargetPic.Image = O End If End Sub Private Sub AxSftTree1_OLEDragDrop(ByVal sender As Object, ByVal e As AxSftTreeLib70._DSftTreeEvents_OLEDragDropEvent) Handles AxSftTree1.OLEDragDrop ' get horizontal extent and width of column 0 Dim horzExtent As Integer horzExtent = AxSftTree1.Items.HorizontalExtentPix Dim firstColumnWidth As Integer firstColumnWidth = AxSftTree1.get_Column(0).WidthPix Dim insertAt As Integer insertAt = AxSftTree1.Items.DropHighlight If insertAt < 0 Then Exit Sub If e.data.GetFormat(SftOLEClipboardConstants.sftCFText) Then Dim lvl As Integer lvl = AxSftTree1.get_Item(insertAt).Level Dim str As String str = e.data.GetData(SftOLEClipboardConstants.sftCFText) Dim newItem As Integer newItem = AxSftTree1.Items.Insert(insertAt + 1, str) AxSftTree1.get_Item(newItem).Level = lvl + 1 End If If e.data.GetFormat(SftOLEClipboardConstants.sftCFDIB) Then AxSftTree1.get_Cell(insertAt, 0).Image.Picture = e.data.GetData(SftOLEClipboardConstants.sftCFDIB) AxSftTree1.get_Cell(insertAt, 0).ImageHAlign = SftTreeHAlignConstants.halignSftTreeRight End If If e.data.GetFormat(SftOLEClipboardConstants.sftCFBitmap) Then AxSftTree1.get_Cell(insertAt, 0).Image.Picture = e.data.GetData(SftOLEClipboardConstants.sftCFBitmap) AxSftTree1.get_Cell(insertAt, 0).ImageHAlign = SftTreeHAlignConstants.halignSftTreeRight End If If e.data.GetFormat(SftOLEClipboardConstants.sftCFFiles) Then AxSftTree1.BulkUpdate = True Dim lvl As Integer lvl = AxSftTree1.get_Item(insertAt).Level Dim newItem As Integer newItem = insertAt + 1 Dim i As Integer For i = e.data.Files.Count To 1 Step -1 newItem = AxSftTree1.Items.Insert(newItem, e.data.Files(i)) AxSftTree1.get_Item(newItem).Level = lvl + 1 Next AxSftTree1.BulkUpdate = False End If ' make horizontal extent and width of column 0 wider than previous ' setting, but never smaller AxSftTree1.ColumnsObj.MakeOptimal() AxSftTree1.Items.RecalcHorizontalExtent() If horzExtent > AxSftTree1.Items.HorizontalExtent Then AxSftTree1.Items.HorizontalExtent = horzExtent End If If firstColumnWidth > AxSftTree1.get_Column(0).WidthPix Then AxSftTree1.get_Column(0).WidthPix = firstColumnWidth End If End Sub Private Sub Picture1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Picture1.MouseDown Dim Data As System.Windows.Forms.DataObject Data = New System.Windows.Forms.DataObject() Data.SetData(DataFormats.Bitmap, True, Picture1.Image) DoDragDrop(Data, DragDropEffects.Copy) End Sub Private Sub Picture2_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Picture2.MouseDown Dim Data As System.Windows.Forms.DataObject Data = New System.Windows.Forms.DataObject() Data.SetData(DataFormats.Dib, True, Picture2.Image) DoDragDrop(Data, DragDropEffects.Copy) End Sub Private Sub Text1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Text1.MouseDown Dim Data As System.Windows.Forms.DataObject Data = New System.Windows.Forms.DataObject() Data.SetData(DataFormats.Text, Text1.Text) DoDragDrop(Data, DragDropEffects.Copy) End Sub End Class