By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,771 Members | 1,669 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,771 IT Pros & Developers. It's quick & easy.

doubleclick won't fire if dragdrop once implemented?

P: n/a
Hello,

I've added drag-and-drop feature to a windows forms label control which is
contained in a panel. And I added a doubleclick event handler to the
drag-and-drop-abled label, but doubleclick event never happen to the label.
What did I wrong? Or is it a .NET bug? (Similar discussions I found:
http://groups.google.co.kr/groups?hl...6newwindow%3D1)

Sample source codes follows:

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

namespace WindowsApplication1
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Label label1;
private System.ComponentModel.Container components = null;
int m_MouseXPositionInLabel1;
int m_MouseYPositionInLabel1;

public Form1()
{
InitializeComponent();
}

protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Code Generated by Windows Form Designer
private void InitializeComponent()
{
this.panel1 = new System.Windows.Forms.Panel();
this.label1 = new System.Windows.Forms.Label();
this.panel1.SuspendLayout();
this.SuspendLayout();
//
// panel1
//
this.panel1.AllowDrop = true;
this.panel1.BackColor =
System.Drawing.Color.FromArgb(((System.Byte)(255)) , ((System.Byte)(255)),
((System.Byte)(192)));
this.panel1.Controls.Add(this.label1);
this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel1.Location = new System.Drawing.Point(0, 0);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(292, 273);
this.panel1.TabIndex = 0;
this.panel1.DragEnter += new
System.Windows.Forms.DragEventHandler(this.panel1_ DragEnter);
this.panel1.DragDrop += new
System.Windows.Forms.DragEventHandler(this.panel1_ DragDrop);
//
// label1
//
this.label1.BackColor =
System.Drawing.Color.FromArgb(((System.Byte)(128)) , ((System.Byte)(255)),
((System.Byte)(128)));
this.label1.Location = new System.Drawing.Point(56, 48);
this.label1.Name = "label1";
this.label1.TabIndex = 0;
this.label1.Text = "label1";
this.label1.DoubleClick += new
System.EventHandler(this.label1_DoubleClick);
this.label1.MouseDown += new
System.Windows.Forms.MouseEventHandler(this.label1 _MouseDown);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.panel1);
this.Name = "Form1";
this.Text = "Form1";
this.panel1.ResumeLayout(false);
this.ResumeLayout(false);

}
#endregion
private void label1_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
// printing out current mouse posision
System.Diagnostics.Debug.WriteLine("X: " + e.X.ToString() + " Y: " +
e.Y.ToString());
this.m_MouseXPositionInLabel1 = e.X;
this.m_MouseYPositionInLabel1 = e.Y;
label1.DoDragDrop(label1, DragDropEffects.Move);
}

private void panel1_DragDrop(object sender,
System.Windows.Forms.DragEventArgs e)
{
// To set the label1's location to the new drag-drop location,
// get e.X and e.Y and subtract form's absolute location.
// "- 4 - this.m_MouseXPositionInLabel1" and "- 23 -
this.m_MouseYPositionInLabel1"
// done for exact drag-and-drop behavior on screen (4 and 23 may differ
on Windows themes?)
Point pt = label1.Location;
pt.X = e.X - this.Left - 4 - this.m_MouseXPositionInLabel1;
pt.Y = e.Y - this.Top - 23 - this.m_MouseYPositionInLabel1;
label1.Location = pt;
}

private void panel1_DragEnter(object sender,
System.Windows.Forms.DragEventArgs e)
{
// giving move effect on the mouse cursor
e.Effect = DragDropEffects.Move;
}

private void label1_DoubleClick(object sender, System.EventArgs e)
{
// PROBLEM -- doubleclick event handler is declared but never entered
System.Diagnostics.Debug.WriteLine("doubleclick event occurred");
}

[STAThread]
static void Main()
{
Application.Run(new Form1());
}
}
}

Nov 16 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.