Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Exemple Glisser déposer en CSharp: Glisser une image d’une zone vers une autre

Exemple,Glisser,déposer,en,CSharp:,Glisser,une,image,d'une,zone,vers,une,autre
{filelink=14625}

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
 
public class Palette : Form
{
    /*      Exemple Glisser Déposer            */
  private System.Windows.Forms.Label lblImage3;
  private System.Windows.Forms.Label lblImage2;
  private System.Windows.Forms.Label lblImage1;
    private ToolTip infoBulle;
    private IContainer components;
  private System.Windows.Forms.Label lblImage4;
 
  public Palette() {
        InitializeComponent();
  }
 
  private void lbl_MouseDown(object sender, MouseEventArgs e)
  {
    Label lbl = (Label)sender;
    lbl.DoDragDrop(lbl.Image, DragDropEffects.Copy);
 
  }
  private void InitializeComponent()
  {
      this.components = new System.ComponentModel.Container();
      System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Palette));
      this.lblImage3 = new System.Windows.Forms.Label();
      this.lblImage2 = new System.Windows.Forms.Label();
      this.lblImage1 = new System.Windows.Forms.Label();
      this.lblImage4 = new System.Windows.Forms.Label();
      this.infoBulle = new System.Windows.Forms.ToolTip(this.components);
      this.SuspendLayout();
      //
      // lblImage3
      //
      this.lblImage3.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
      this.lblImage3.Image = ((System.Drawing.Image)(resources.GetObject("lblImage3.Image")));
      this.lblImage3.Location = new System.Drawing.Point(12, 113);
      this.lblImage3.Name = "lblImage3";
      this.lblImage3.Size = new System.Drawing.Size(56, 48);
      this.lblImage3.TabIndex = 6;
      this.infoBulle.SetToolTip(this.lblImage3, "Glisser cette image vers la zone de dessin");
      this.lblImage3.MouseDown += new System.Windows.Forms.MouseEventHandler(this.lbl_MouseDown);
      //
      // lblImage2
      //
      this.lblImage2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
      this.lblImage2.Image = ((System.Drawing.Image)(resources.GetObject("lblImage2.Image")));
      this.lblImage2.Location = new System.Drawing.Point(12, 61);
      this.lblImage2.Name = "lblImage2";
      this.lblImage2.Size = new System.Drawing.Size(56, 48);
      this.lblImage2.TabIndex = 5;
      this.infoBulle.SetToolTip(this.lblImage2, "Glisser cette image vers la zone de dessin");
      this.lblImage2.MouseDown += new System.Windows.Forms.MouseEventHandler(this.lbl_MouseDown);
      //
      // lblImage1
      //
      this.lblImage1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
      this.lblImage1.Image = ((System.Drawing.Image)(resources.GetObject("lblImage1.Image")));
      this.lblImage1.Location = new System.Drawing.Point(12, 9);
      this.lblImage1.Name = "lblImage1";
      this.lblImage1.Size = new System.Drawing.Size(56, 48);
      this.lblImage1.TabIndex = 4;
      this.infoBulle.SetToolTip(this.lblImage1, "Glisser cette image vers la zone de dessin");
      this.lblImage1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.lbl_MouseDown);
      //
      // lblImage4
      //
      this.lblImage4.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
      this.lblImage4.Image = ((System.Drawing.Image)(resources.GetObject("lblImage4.Image")));
      this.lblImage4.Location = new System.Drawing.Point(12, 164);
      this.lblImage4.Name = "lblImage4";
      this.lblImage4.Size = new System.Drawing.Size(56, 48);
      this.lblImage4.TabIndex = 6;
      this.infoBulle.SetToolTip(this.lblImage4, "Glisser cette image vers la zone de dessin");
      this.lblImage4.MouseDown += new System.Windows.Forms.MouseEventHandler(this.lbl_MouseDown);
      //
      // Palette
      //
      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
      this.ClientSize = new System.Drawing.Size(83, 230);
      this.Controls.Add(this.lblImage4);
      this.Controls.Add(this.lblImage3);
      this.Controls.Add(this.lblImage2);
      this.Controls.Add(this.lblImage1);
      this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
      this.Name = "Palette";
      this.ShowInTaskbar = false;
      this.Text = "Palette";
      this.ResumeLayout(false);
 
  }
 
  [STAThread]
  static void Main()
  {
    Application.Run(new zoneDessin());
  }
 
}
 
  public class zoneDessin : Form
  {
    private System.Windows.Forms.PictureBox piczoneDessin;
 
    public zoneDessin()
    {
      InitializeComponent();
    }
 
    private void zoneDessin_Load(object sender, EventArgs e)
    {
      Palette frmTool = new Palette();
      this.AddOwnedForm(frmTool);
      frmTool.Show();
      piczoneDessin.AllowDrop = true;
    }
 
    private void piczoneDessin_DragEnter(object sender, DragEventArgs e)
    {
      if (e.Data.GetDataPresent(DataFormats.Bitmap))
      {
        e.Effect = DragDropEffects.Copy;
      }
      else
      {
        e.Effect = DragDropEffects.None;
      }
    }
 
    private void piczoneDessin_DragDrop(object sender, DragEventArgs e)
    {
      Graphics g = piczoneDessin.CreateGraphics();
      g.DrawImage((Image)e.Data.GetData(DataFormats.Bitmap),
        new Point(e.X - this.Left, e.Y - this.Top));
 
    }
     private void InitializeComponent()
    {
      this.piczoneDessin = new System.Windows.Forms.PictureBox();
      ((System.ComponentModel.ISupportInitialize)(this.piczoneDessin)).BeginInit();
      this.SuspendLayout();
      //
      // piczoneDessin
      //
      this.piczoneDessin.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
            | System.Windows.Forms.AnchorStyles.Left)
            | System.Windows.Forms.AnchorStyles.Right)));
      this.piczoneDessin.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
      this.piczoneDessin.Location = new System.Drawing.Point(1, 2);
      this.piczoneDessin.Name = "piczoneDessin";
      this.piczoneDessin.Size = new System.Drawing.Size(377, 270);
      this.piczoneDessin.TabIndex = 2;
      this.piczoneDessin.TabStop = false;
      this.piczoneDessin.DragDrop += new System.Windows.Forms.DragEventHandler(this.piczoneDessin_DragDrop);
      this.piczoneDessin.DragEnter += new System.Windows.Forms.DragEventHandler(this.piczoneDessin_DragEnter);
      //
      // zoneDessin
      //
      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
      this.ClientSize = new System.Drawing.Size(379, 274);
      this.Controls.Add(this.piczoneDessin);
      this.Name = "zoneDessin";
      this.Text = "Zone de dessin";
      this.Load += new System.EventHandler(this.zoneDessin_Load);
      ((System.ComponentModel.ISupportInitialize)(this.piczoneDessin)).EndInit();
      this.ResumeLayout(false);
    }
  }

No comments yet.

Leave a Comment