Fake Drag And Drop : Drag Drop « GUI Windows Form « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Date Time
8.Design Patterns
9.Development Class
10.Event
11.File Stream
12.Generics
13.GUI Windows Form
14.Internationalization I18N
15.Language Basics
16.LINQ
17.Network
18.Office
19.Reflection
20.Regular Expressions
21.Security
22.Services Event
23.Thread
24.Web Services
25.Windows
26.Windows Presentation Foundation
27.XML
28.XML LINQ
C# Book
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » GUI Windows Form » Drag DropScreenshots 
Fake Drag And Drop
Fake Drag And Drop

/*
User Interfaces in C#: Windows Forms and Custom Controls
by Matthew MacDonald

Publisher: Apress
ISBN: 1590590457
*/

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace FakeDragAndDrop
{
  /// <summary>
  /// Summary description for FakeDragAndDrop.
  /// </summary>
  public class FakeDragAndDrop : System.Windows.Forms.Form
  {
    internal System.Windows.Forms.Label lblDragger;
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.Container components = null;

    public FakeDragAndDrop()
    {
      //
      // 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 Disposebool disposing )
    {
      ifdisposing )
      {
        if (components != null
        {
          components.Dispose();
        }
      }
      base.Disposedisposing );
    }

    #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.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(FakeDragAndDrop));
      this.lblDragger = new System.Windows.Forms.Label();
      this.SuspendLayout();
      // 
      // lblDragger
      // 
      this.lblDragger.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
      this.lblDragger.Image = ((System.Drawing.Bitmap)(resources.GetObject("lblDragger.Image")));
      this.lblDragger.Location = new System.Drawing.Point(110105);
      this.lblDragger.Name = "lblDragger";
      this.lblDragger.Size = new System.Drawing.Size(7256);
      this.lblDragger.TabIndex = 2;
      this.lblDragger.MouseUp += new System.Windows.Forms.MouseEventHandler(this.lblDragger_MouseUp);
      this.lblDragger.MouseMove += new System.Windows.Forms.MouseEventHandler(this.lblDragger_MouseMove);
      this.lblDragger.MouseDown += new System.Windows.Forms.MouseEventHandler(this.lblDragger_MouseDown);
      // 
      // FakeDragAndDrop
      // 
      this.AutoScaleBaseSize = new System.Drawing.Size(513);
      this.ClientSize = new System.Drawing.Size(292266);
      this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                      this.lblDragger});
      this.Name = "FakeDragAndDrop";
      this.Text = "Fake Drag And Drop";
      this.ResumeLayout(false);

    }
    #endregion

    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main() 
    {
      Application.Run(new FakeDragAndDrop());
    }

    // Keep track of when fake "drag and drop" mode is enabled.
    private bool isDragging = false;

    // Store the location where the user clicked the control.
    private int clickOffsetX, clickOffsetY;

    // Start dragging.
    private void lblDragger_MouseDown(System.Object sender,
      System.Windows.Forms.MouseEventArgs e)
    {
      isDragging = true;
      clickOffsetX = e.X;
      clickOffsetY = e.Y;
    }

    // End dragging.
    private void lblDragger_MouseUp(System.Object sender,
      System.Windows.Forms.MouseEventArgs e)
    {
      isDragging = false;
    }

    // Move the control (during dragging).
    private void lblDragger_MouseMove(System.Object sender,
      System.Windows.Forms.MouseEventArgs e)
    {
      if (isDragging == true)
      {
        // The control coordinates are converted into form coordinates
        // by adding the label position offset.
        // The offset where the user clicked in the control is also
        // accounted for. Otherwise, it looks like the top-left corner
        // of the label is attached to the mouse.
        lblDragger.Left = e.X + lblDragger.Left - clickOffsetX;
        lblDragger.Top = e.Y + lblDragger.Top - clickOffsetY;
      }
    }

  }
}


           
       
FakeDragAndDrop.zip( 23 k)
Related examples in the same category
1.Image Drop
2.Drag and drop inside a containerDrag and drop inside a container
3.Drag and drop image to another windowDrag and drop image to another window
4.Drag and drop the PictureBoxDrag and drop the PictureBox
java2s.com  |  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.