Solved

MouseDown Event Not firing on user control

Posted on 2011-03-11
6
2,029 Views
Last Modified: 2013-12-17
I'm new to working with user controls in C#. I have created a small user control that consists of a panel, picture, and label. I want to be able to drag and drop the user control. I have the following code:

        private void imageContainer1_MouseDown(object sender, MouseEventArgs e)
        {
            imageContainer1.DoDragDrop(imageContainer1, DragDropEffects.All);
        }

Open in new window


The problem I am having is that the MouseDown event is not firing off on the user control. Is there something that I am missing? Am I not able to drag/drop the entire control like any other control? Thanks for your help.
0
Comment
Question by:aceswildab1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 35113396
The MouseDown() event will fire for whatever control your are over so if the mouse is over the Panel then the Panel will get the MouseDown() event.  If the mouse is over the PictureBox then the PictureBox will get the event, etc...

If you want to be able to move it from anywhere within the UserControl then you need to wire up ALL the controls so that they either fire that existing handler or they all have their own handlers that call similar code.
0
 
LVL 8

Expert Comment

by:dericstone
ID: 35122974
Did you subscribe to the MouseDown event using the event handler you created? See code below.

On the other hand, I'm not entirely sure you can actually drag a control, but I could be wrong. I know you can drag an object from a ListBox or from Windows Explorer onto a control. But dragging a control...I don't know.
this.imageContainer1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.imageContainer1_MouseDown);

Open in new window

0
 

Author Comment

by:aceswildab1
ID: 35127230
I know that it is possible to move an entire control. I've been testing it out with other controls. I also do have the MouseDown event for the user control hooked up correctly. The code is in place.

Idle, are you saying that within my user control, I would need to enable the drag/drop code for each and every control within it to get the user control itself to drag? The user control wouldn't just drag and take everything that it contains with it?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:aceswildab1
ID: 35127462
I've set the mousedown events on the controls within the user control. This allows me to do a drag/drop with those controls within it. Is there a way of doing drag/drop with the entire user control as a whole or will it only work with the controls within it? (IE - allowing me to move the entire control rather than the individual parts within)
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 35127855
Yes...you can drag it as a whole.  Wire up everything to the same handler and only call drag with the UserControl itself as the object being worked on.

Show me your code...
0
 

Author Closing Comment

by:aceswildab1
ID: 35128453
That's exactly what I needed. It works just the way I was wanting it to. Thanks for the help!!!
0

Featured Post

Is Your Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question