Hide

SftBox/OCX 5.0 - Combo Box Control

Display
Print

DragDrop Sample (C#)

This sample illustrates drag & drop.

The source code is located at C:\Program Files (x86)\Softelvdm\SftBox OCX 5.0\Samples\Visual Studio - CSharp\DragDrop\Form1.cs or C:\Program Files\Softelvdm\SftBox OCX 5.0\Samples\Visual Studio - CSharp\DragDrop\Form1.cs (on 32-bit Windows versions).

private void cancelButton_Click(object sender, System.EventArgs e)
{
    Application.Exit();
}

private void comboTarget_DragOver(object sender, System.Windows.Forms.DragEventArgs e)
{
    MessageBox.Show("Hi");
}

private void Form1_Load(object sender, System.EventArgs e)
{
    comboSource.Items.Add("An Item");
    comboSource.Items.Add("Another Item");
    comboSource.Items.Add("Last Item");
    comboSource.Columns.MakeOptimal(0);
    comboSource.Items.RecalcHorizontalExtent(0);

    comboTarget.Items.Add("A Source Item");
    comboTarget.Items.Add("Another Source Item");
    comboTarget.Items.Add("Last Source Item");
    comboTarget.Columns.MakeOptimal(0);
    comboTarget.Items.RecalcHorizontalExtent(0);
}

private void comboSource_DragStarting(object sender, AxSftBoxLib50._ISftBoxEvents_DragStartingEvent e)
{
    comboSource.OLEDrag();
}

private void comboSource_OLEStartDrag(object sender, AxSftBoxLib50._ISftBoxEvents_OLEStartDragEvent e)
{
    e.allowedEffects = vbDropEffectCopy | vbDropEffectMove;
    string textData = comboSource.get_Cell(comboSource.Items.Selection, 0).Text;
    e.data.SetData(textData, SftOLEClipboardConstants.sftCFText);
}

private void comboTarget_OLEDragOver(object sender, AxSftBoxLib50._ISftBoxEvents_OLEDragOverEvent e)
{
    if (e.state == SftBoxOLEDragOverConstants.enterSftBox) {
        // Show the drop down portion
        comboTarget.DropDown.Dropped = true;
    } else if (e.state == SftBoxOLEDragOverConstants.leaveSftBox) {
        // Hide the drop down portion with a delay, in case the
        // user is moving from/to the static or drop down portion
        comboTarget.DropDown.RollUp(500);  // 1/2 second
    }
}

private void comboTarget_OLEDragDrop(object sender, AxSftBoxLib50._ISftBoxEvents_OLEDragDropEvent e)
{
    if (e.data.GetFormat((short) SftOLEClipboardConstants.sftCFText)) {
        int itemIndex = comboTarget.Items.Insert(e.data.GetData(SftOLEClipboardConstants.sftCFText) as string, comboTarget.Items.DropIndex);
        comboTarget.Items.Selection = itemIndex;
    }
    if (e.data.GetFormat((short) SftOLEClipboardConstants.sftCFBitmap)) {
        int itemIndex = comboTarget.Items.Insert("A Bitmap", comboTarget.Items.DropIndex);
        object o = e.data.GetData(SftOLEClipboardConstants.sftCFBitmap);
        comboTarget.get_Item(itemIndex).Image.Picture = o as stdole.IPictureDisp;
        comboTarget.Items.Selection = itemIndex;
    }
    if (e.data.GetFormat((short) SftOLEClipboardConstants.sftCFFiles)) {
        int itemIndex = -1;
        int toIndex = comboTarget.Items.DropIndex;
        foreach (string s in e.data.Files) {
            itemIndex = comboTarget.Items.Insert(s, toIndex);
            toIndex = toIndex + 1;
        }
        comboTarget.Items.Selection = itemIndex;
    }
    comboTarget.Columns.MakeOptimal(0);
    comboTarget.Items.RecalcHorizontalExtent(0);
}

private void dragLabel_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
    dragLabel.DoDragDrop(dragLabel.Text, DragDropEffects.Copy);
}

private void pictureBox1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
    dragLabel.DoDragDrop(pictureBox1.Image, DragDropEffects.Copy);
}

Last Updated 08/13/2020 - (email)
© 2024 Softel vdm, Inc.