using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using AxSftBoxLib45;
using SftBoxLib45;
using Softelvdm.OLEConvert;
namespace DragDrop
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
const int vbDropEffectCopy = 1;
const int vbDropEffectMove = 2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Label label5;
private AxSftBoxLib45.AxSftBox comboSource;
private AxSftBoxLib45.AxSftBox comboTarget;
private System.Windows.Forms.Label dragLabel;
private System.Windows.Forms.Button closeButton;
private System.Windows.Forms.Label label6;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
this.closeButton = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.comboSource = new AxSftBoxLib45.AxSftBox();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.label5 = new System.Windows.Forms.Label();
this.comboTarget = new AxSftBoxLib45.AxSftBox();
this.dragLabel = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.comboSource)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.comboTarget)).BeginInit();
this.SuspendLayout();
//
// closeButton
//
this.closeButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.closeButton.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.closeButton.Location = new System.Drawing.Point(409, 8);
this.closeButton.Name = "closeButton";
this.closeButton.Size = new System.Drawing.Size(88, 30);
this.closeButton.TabIndex = 0;
this.closeButton.Text = "Close";
this.closeButton.Click += new System.EventHandler(this.cancelButton_Click);
//
// label1
//
this.label1.Location = new System.Drawing.Point(7, 8);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(395, 45);
this.label1.TabIndex = 1;
this.label1.Text = "This sample shows OLE drag && drop. Simply drag data from the left (Drag Sources" +
") to the combo box on the right (Drop Target).";
//
// comboSource
//
this.comboSource.Location = new System.Drawing.Point(7, 61);
this.comboSource.Name = "comboSource";
this.comboSource.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("comboSource.OcxState")));
this.comboSource.Size = new System.Drawing.Size(227, 43);
this.comboSource.TabIndex = 2;
this.comboSource.DragStarting += new AxSftBoxLib45._ISftBoxEvents_DragStartingEventHandler(this.comboSource_DragStarting);
this.comboSource.OLEStartDrag += new AxSftBoxLib45._ISftBoxEvents_OLEStartDragEventHandler(this.comboSource_OLEStartDrag);
//
// label2
//
this.label2.Location = new System.Drawing.Point(7, 114);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(227, 53);
this.label2.TabIndex = 4;
this.label2.Text = "Note: The drop down portion must be used to start a drag && drop from the above " +
"combo box.";
//
// label3
//
this.label3.Location = new System.Drawing.Point(263, 129);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(227, 83);
this.label3.TabIndex = 5;
this.label3.Text = "Drop items in the above combo box. The drop down portion will automatically beco" +
"me visible as the cursor moves over the control.";
//
// label4
//
this.label4.Font = new System.Drawing.Font("Microsoft Sans Serif", 10.2F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label4.Location = new System.Drawing.Point(7, 174);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(241, 23);
this.label4.TabIndex = 6;
this.label4.Text = "More Drag Sources";
//
// pictureBox1
//
this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
this.pictureBox1.Location = new System.Drawing.Point(7, 235);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(30, 30);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;
this.pictureBox1.TabIndex = 8;
this.pictureBox1.TabStop = false;
this.pictureBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseDown);
//
// label5
//
this.label5.Location = new System.Drawing.Point(58, 235);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(278, 45);
this.label5.TabIndex = 9;
this.label5.Text = "You can also drag file names from Windows Explorer to the drop target on the righ" +
"t.";
//
// comboTarget
//
this.comboTarget.AllowDrop = true;
this.comboTarget.Location = new System.Drawing.Point(263, 61);
this.comboTarget.Name = "comboTarget";
this.comboTarget.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("comboTarget.OcxState")));
this.comboTarget.Size = new System.Drawing.Size(227, 43);
this.comboTarget.TabIndex = 10;
this.comboTarget.OLEDragDrop += new AxSftBoxLib45._ISftBoxEvents_OLEDragDropEventHandler(this.comboTarget_OLEDragDrop);
this.comboTarget.OLEDragOver += new AxSftBoxLib45._ISftBoxEvents_OLEDragOverEventHandler(this.comboTarget_OLEDragOver);
//
// dragLabel
//
this.dragLabel.Location = new System.Drawing.Point(7, 204);
this.dragLabel.Name = "dragLabel";
this.dragLabel.Size = new System.Drawing.Size(205, 23);
this.dragLabel.TabIndex = 11;
this.dragLabel.Text = "Drag this text to the drop target";
this.dragLabel.MouseDown += new System.Windows.Forms.MouseEventHandler(this.dragLabel_MouseDown);
//
// label6
//
this.label6.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label6.Location = new System.Drawing.Point(216, 185);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(280, 47);
this.label6.TabIndex = 12;
this.label6.Text = "Click on the SftBox/OCX control above and hit F1 to access help information for S" +
"ftBox/OCX 4.5";
this.label6.Visible = false;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.CancelButton = this.closeButton;
this.ClientSize = new System.Drawing.Size(505, 280);
this.Controls.Add(this.label6);
this.Controls.Add(this.dragLabel);
this.Controls.Add(this.comboTarget);
this.Controls.Add(this.label5);
this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.comboSource);
this.Controls.Add(this.label1);
this.Controls.Add(this.closeButton);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "Form1";
this.Text = "Softel vdm, Inc. - DragDrop Sample";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.comboSource)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.comboTarget)).EndInit();
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
//--locate-marker--
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, AxSftBoxLib45._ISftBoxEvents_DragStartingEvent e)
{
comboSource.OLEDrag();
}
private void comboSource_OLEStartDrag(object sender, AxSftBoxLib45._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, AxSftBoxLib45._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, AxSftBoxLib45._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);
}
}
}