473,898 Members | 3,702 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Drag and drop labels in a panel

Hi to all,

I'm writing a windows form application that has a panel with some
labels in it.
I need to let the user move these labels with drag and drop inside the
panel. How can I do it?
I now how to drag and drop for example the text contained in a textbox,
but not the whole control.
I read an article called "Fake drag and drop" that works without
dragdrop event and it's not so good.

Thanks in advance.
Vincent

Jan 23 '07 #1
6 20360
Hi,

DnD is used to move data around, for example you select a text in one
application and you move it to some other application - you move the data.
The same effect you can get by copy/paste the text to/from the clipboard
If grab a window by its caption and start moving it around this has nothing
to do with drag and drop; there is no data that has been moved around.

So what you want to do - move the label's data (I guess the text) or you
want to move the lable control around just like you would move a window by
grabing it handle?
--
Stoitcho Goutsev (100)

"Blkpower" <we*******@elet trunina.comwrot e in message
news:11******** **************@ a75g2000cwd.goo glegroups.com.. .
Hi to all,

I'm writing a windows form application that has a panel with some
labels in it.
I need to let the user move these labels with drag and drop inside the
panel. How can I do it?
I now how to drag and drop for example the text contained in a textbox,
but not the whole control.
I read an article called "Fake drag and drop" that works without
dragdrop event and it's not so good.

Thanks in advance.
Vincent

Jan 24 '07 #2

Hi,

thanks for your answer.
What I need to do is to move the whole control, not only the text.
Any ideas about how to do this?

Thanks
Vincent

On 24 Gen, 16:40, "Stoitcho Goutsev \(100\)" <1...@100.comwr ote:
Hi,

DnD is used to move data around, for example you select a text in one
application and you move it to some other application - you move the data.
The same effect you can get by copy/paste the text to/from the clipboard
If grab a window by its caption and start moving it around this has nothing
to do with drag and drop; there is no data that has been moved around.

So what you want to do - move the label's data (I guess the text) or you
want to move the lable control around just like you would move a window by
grabing it handle?

--
Stoitcho Goutsev (100)

"Blkpower" <webmas...@elet trunina.comwrot e in messagenews:11* *************** ******@a75g2000 cwd.googlegroup s.com...
Hi to all,
I'm writing a windows form application that has a panel with some
labels in it.
I need to let the user move these labels with drag and drop inside the
panel. How can I do it?
I now how to drag and drop for example the text contained in a textbox,
but not the whole control.
I read an article called "Fake drag and drop" that works without
dragdrop event and it's not so good.
Thanks in advance.
Vincent- Nascondi testo tra virgolette -- Mostra testo tra virgolette -
Jan 30 '07 #3
Here's how I managed draggable PictureBoxes in a Panel.

I didn't use the normal drag/drop mechanisms at all; instead, I
handled the mouse events and used a timer to move the items. This
might be a stupid way to do it, but it works. Of course, you need to
connect up the piece_ event handlers for each separate item in your
Panel, which can be done with a simple foreach loop at the beginning.

Eq.
private PictureBox _draggedPiece;
private Point _dragLocation;

private void piece_MouseDown (object sender, MouseEventArgs e)
{
_draggedPiece = picPiece;
_draggedPiece.B ringToFront();
}

private void piece_MouseUp(o bject sender, MouseEventArgs e)
{
_draggedPiece = null;
pnlMap.Invalida te();
}

private void piece_MouseMove (object sender, MouseEventArgs e)
{
if (_draggedPiece != null)
{
int x = _draggedPiece.L eft + e.X;
int y = _draggedPiece.T op + e.Y;

_dragLocation = new Point(x, y);
}
}

private void tmrDragMove_Tic k(object sender, System.EventArg s e)
{
// tmrDragMove is a Timer that fires many times a second

if (_draggedPiece != null)
{
_draggedPiece.L ocation = _dragLocation;
pnlMap.Invalida te();
}
}
Jan 30 '07 #4
Vincent,

Derive from the label control and override its WndProc

private const int WM_NCHITTEST = 0x84;
private const int HTCAPTION = 0x2;
private const int HTCLIENT = 0x1;
protected override void WndProc(ref Message m)
{
base.WndProc (ref m);
if(m.Msg == WM_NCHITTEST && m.Result == new IntPtr(HTCLIENT ))
{
m.Result = new IntPtr(HTCAPTIO N);

}
That should work for any control
--
HTH
Stoitcho Goutsev (100)
"Blkpower" <we*******@elet trunina.comwrot e in message
news:11******** **************@ l53g2000cwa.goo glegroups.com.. .
>
Hi,

thanks for your answer.
What I need to do is to move the whole control, not only the text.
Any ideas about how to do this?

Thanks
Vincent

On 24 Gen, 16:40, "Stoitcho Goutsev \(100\)" <1...@100.comwr ote:
>Hi,

DnD is used to move data around, for example you select a text in one
application and you move it to some other application - you move the
data.
The same effect you can get by copy/paste the text to/from the clipboard
If grab a window by its caption and start moving it around this has
nothing
to do with drag and drop; there is no data that has been moved around.

So what you want to do - move the label's data (I guess the text) or you
want to move the lable control around just like you would move a window
by
grabing it handle?

--
Stoitcho Goutsev (100)

"Blkpower" <webmas...@elet trunina.comwrot e in
messagenews:11 *************** *******@a75g200 0cwd.googlegrou ps.com...
Hi to all,
I'm writing a windows form application that has a panel with some
labels in it.
I need to let the user move these labels with drag and drop inside the
panel. How can I do it?
I now how to drag and drop for example the text contained in a textbox,
but not the whole control.
I read an article called "Fake drag and drop" that works without
dragdrop event and it's not so good.
Thanks in advance.
Vincent- Nascondi testo tra virgolette -- Mostra testo tra virgolette -

Jan 30 '07 #5
On 30 Gen, 15:50, "Paul E Collins" <find_my_real_a ddr...@CL4.org>
wrote:
Here's how I managed draggable PictureBoxes in a Panel.

I didn't use the normal drag/drop mechanisms at all; instead, I
handled the mouse events and used a timer to move the items. This
might be a stupid way to do it, but it works. Of course, you need to
connect up the piece_ event handlers for each separate item in your
Panel, which can be done with a simple foreach loop at the beginning.

Eq.

private PictureBox _draggedPiece;
private Point _dragLocation;

private void piece_MouseDown (object sender, MouseEventArgs e)
{
_draggedPiece = picPiece;
_draggedPiece.B ringToFront();

}

private void piece_MouseUp(o bject sender, MouseEventArgs e)
{
_draggedPiece = null;
pnlMap.Invalida te();

}

private void piece_MouseMove (object sender, MouseEventArgs e)
{
if (_draggedPiece != null)
{
int x = _draggedPiece.L eft + e.X;
int y = _draggedPiece.T op + e.Y;

_dragLocation = new Point(x, y);
}

}

private void tmrDragMove_Tic k(object sender, System.EventArg s e)
{
// tmrDragMove is a Timer that fires many times a second

if (_draggedPiece != null)
{
_draggedPiece.L ocation = _dragLocation;
pnlMap.Invalida te();
}

}- Nascondi testo tra virgolette -

- Mostra testo tra virgolette -
Hi,
thanks for your answer.
I found and example on internet called "Fakedraganddro p" very similar
to your solution. The problem is that is not so performant, I think I
can do it better.

Thanks
Vincent

Feb 1 '07 #6
On 30 Gen, 17:19, "Stoitcho Goutsev \(100\)" <1...@100.comwr ote:
Vincent,

Derive from the label control and override its WndProc

private const int WM_NCHITTEST = 0x84;
private const int HTCAPTION = 0x2;
private const int HTCLIENT = 0x1;

protected override void WndProc(ref Message m)
{
base.WndProc (ref m);
if(m.Msg == WM_NCHITTEST && m.Result == new IntPtr(HTCLIENT ))
{
m.Result = new IntPtr(HTCAPTIO N);

}

That should work for any control

--
HTH
Stoitcho Goutsev (100)"Blkpower" <webmas...@elet trunina.comwrot e in message

news:11******** **************@ l53g2000cwa.goo glegroups.com.. .


Hi,
thanks for your answer.
What I need to do is to move the whole control, not only the text.
Any ideas about how to do this?
Thanks
Vincent
On 24 Gen, 16:40, "Stoitcho Goutsev \(100\)" <1...@100.comwr ote:
Hi,
DnD is used to move data around, for example you select a text in one
application and you move it to some other application - you move the
data.
The same effect you can get by copy/paste the text to/from the clipboard
If grab a window by its caption and start moving it around this has
nothing
to do with drag and drop; there is no data that has been moved around.
So what you want to do - move the label's data (I guess the text) or you
want to move the lable control around just like you would move a window
by
grabing it handle?
--
Stoitcho Goutsev (100)
"Blkpower" <webmas...@elet trunina.comwrot e in
messagenews:11* *************** ******@a75g2000 cwd.googlegroup s.com...
Hi to all,
I'm writing a windows form application that has a panel with some
labels in it.
I need to let the user move these labels with drag and drop inside the
panel. How can I do it?
I now how to drag and drop for example the text contained in a textbox,
but not the whole control.
I read an article called "Fake drag and drop" that works without
dragdrop event and it's not so good.
Thanks in advance.
Vincent- Nascondi testo tra virgolette -- Mostra testo tra virgolette -- Nascondi testo tra virgolette -

- Mostra testo tra virgolette -
Hi, thanks.
I tried as you suggested but was not able to see it working.
This is my class:

namespace UtilityConfigMa nager
{
public class MovingLabel: Label
{

private const int WM_NCHITTEST = 0x84;
private const int HTCAPTION = 0x2;
private const int HTCLIENT = 0x1;

public MovingLabel()
{
}

protected override void WndProc(ref Message m)
{
base.WndProc (ref m);
if(m.Msg == WM_NCHITTEST && m.Result == new IntPtr(HTCLIENT ))
{
m.Result = new IntPtr(HTCAPTIO N);
}
}
}
}

and this is my form where I try to use the control:

public class Form2 : System.Windows. Forms.Form
{
private UtilityConfigMa nager.MovingLab el mlabel1;
private System.Componen tModel.Containe r components = null;

public Form2()
{
InitializeCompo nent();
}

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

private void InitializeCompo nent()
{
this.mlabel1 = new UtilityConfigMa nager.MovingLab el();
this.SuspendLay out();
//
// mlabel1
//
this.mlabel1.Al lowDrop = true;
this.mlabel1.Lo cation = new System.Drawing. Point(72, 48);
this.mlabel1.Na me = "mlabel1";
this.mlabel1.Ta bIndex = 1;
this.mlabel1.Te xt = "mlabel1";
//
// Form2
//
this.AutoScaleB aseSize = new System.Drawing. Size(5, 13);
this.ClientSize = new System.Drawing. Size(292, 273);
this.Controls.A dd(this.mlabel1 );
this.Name = "Form2";
this.Text = "Form2";
this.ResumeLayo ut(false);

}
}

Where Am I wrong?

Thanks

Feb 1 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
7286
by: zav | last post by:
Hi all i`m having a small problem with windows forms, i`m attempting to provide the following functionality to a form. Ability to drag and drop another form onto a form and then to dock this form... Quite a mouthful however a good example of this is within the VS.NET 6 IDE. Grab your solution explorer panel and drop it outside of the IDE, then drag/drop it back in and watch it dock.
1
1630
by: Kevin L | last post by:
I have a Panel control that I currently allow the user to drag and reposition on a form at runtime. This Panel control contains a Label control. I would like to allow the user to drag the PANEL by clicking on the LABEL and dragging. Is there a way to do this?
1
1118
by: Brad | last post by:
Okay, I am learning about Drag/Drop operations so I am green when it comes to this. I have a form that draws several optional labels that are single-bordered. I also have a dozen colored labels that I want to drop over these "drawn" labels and on the drop, I want to color the "drawn" label the color of the dragged label. Make sense? The problem I am running into is based on certain criteria these "drawn" labels are named and can...
0
2179
by: MrNobody | last post by:
I have a custom Panel which will have smaller custom Panels added and drawn within it. I want to be able to re-order the arrangement of the inner Panels using drag n drop, and I want to do this graphically by actually drawing the inner Panel being dragged around, instead of just the default DragDropEffects graphics. But I can't seem to get this to work... What I tried is when you click on an inner Panel you acitvate a DragNDrop with...
1
1679
by: Taptu¶ | last post by:
Hi, Is there any way to use D&D functionality with panel ? Ex. I have 2 panels: panel 1 and panel2 I want to drag panel1 over panel2 and change parent value of panel1 after Drop panel1.parent = panel2; Best regards Taptu¶
1
2314
by: SteveDouglas | last post by:
Hi all, I am currently writing an application in VB.NET that has a lot of controls (treeviews/listviews/labels and so forth) that represent "things" that need to be draggable from place to place, including between controls and windows. In the past when I've implemented Drag and Drop in other projects, I've always passed the item being dragged (for example the listviewitem or the treenode) to the DoDragDrop and then retrieved it in the...
6
6549
by: Alfonso2968 | last post by:
Hello, If someone can help plz. I have searched everything and all I can find is how to drag and drop within a form from panel to panel. What I need to do is Drag an image from the desktop or from an open folder to a panel on my form. This will be done for a few images and then on Buttonclik I need to save each image in its own folder.
1
1591
by: dvsriram | last post by:
Hii , i am creating a control i..e toolstrip in vb.net2005 that contains ,textbox,label,radiobutton ,printer,zoom options of a page .When i click a label it should place at any place on panel .now my problem is i amnot able to drag the control and place it anywhere on panel which is runtime generated control . i am not able to use correctly the panel1_mousedown and mousemove . please solve this problem and ihave to create properties for...
4
3670
by: Jeff | last post by:
Hello, I am trying to drag and drop a label control from one cell in a tablelayoutpanel to another (VB2005). There is no problem if both cells are visible, but i cannot get the tablelayoutpanel to scroll in any direction (autoscroll is on), when the cell i want to drag to is no currently visible and requires scrolling to get to see it. Any suggestions would be greatly appreciated.
0
9993
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9841
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10484
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9662
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8036
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7187
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6077
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4706
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4296
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.