473,395 Members | 1,629 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 20309
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*******@elettrunina.comwrote in message
news:11**********************@a75g2000cwd.googlegr oups.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.comwrote:
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...@elettrunina.comwrote in messagenews:11**********************@a75g2000cwd.g ooglegroups.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.BringToFront();
}

private void piece_MouseUp(object sender, MouseEventArgs e)
{
_draggedPiece = null;
pnlMap.Invalidate();
}

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

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

private void tmrDragMove_Tick(object sender, System.EventArgs e)
{
// tmrDragMove is a Timer that fires many times a second

if (_draggedPiece != null)
{
_draggedPiece.Location = _dragLocation;
pnlMap.Invalidate();
}
}
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(HTCAPTION);

}
That should work for any control
--
HTH
Stoitcho Goutsev (100)
"Blkpower" <we*******@elettrunina.comwrote in message
news:11**********************@l53g2000cwa.googlegr oups.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.comwrote:
>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...@elettrunina.comwrote in
messagenews:11**********************@a75g2000cwd. googlegroups.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_addr...@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.BringToFront();

}

private void piece_MouseUp(object sender, MouseEventArgs e)
{
_draggedPiece = null;
pnlMap.Invalidate();

}

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

_dragLocation = new Point(x, y);
}

}

private void tmrDragMove_Tick(object sender, System.EventArgs e)
{
// tmrDragMove is a Timer that fires many times a second

if (_draggedPiece != null)
{
_draggedPiece.Location = _dragLocation;
pnlMap.Invalidate();
}

}- Nascondi testo tra virgolette -

- Mostra testo tra virgolette -
Hi,
thanks for your answer.
I found and example on internet called "Fakedraganddrop" 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.comwrote:
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(HTCAPTION);

}

That should work for any control

--
HTH
Stoitcho Goutsev (100)"Blkpower" <webmas...@elettrunina.comwrote in message

news:11**********************@l53g2000cwa.googlegr oups.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.comwrote:
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...@elettrunina.comwrote in
messagenews:11**********************@a75g2000cwd.g ooglegroups.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 UtilityConfigManager
{
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(HTCAPTION);
}
}
}
}

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

public class Form2 : System.Windows.Forms.Form
{
private UtilityConfigManager.MovingLabel mlabel1;
private System.ComponentModel.Container components = null;

public Form2()
{
InitializeComponent();
}

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

private void InitializeComponent()
{
this.mlabel1 = new UtilityConfigManager.MovingLabel();
this.SuspendLayout();
//
// mlabel1
//
this.mlabel1.AllowDrop = true;
this.mlabel1.Location = new System.Drawing.Point(72, 48);
this.mlabel1.Name = "mlabel1";
this.mlabel1.TabIndex = 1;
this.mlabel1.Text = "mlabel1";
//
// Form2
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.mlabel1);
this.Name = "Form2";
this.Text = "Form2";
this.ResumeLayout(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
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...
1
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...
1
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...
0
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...
1
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...
1
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,...
6
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...
1
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...
4
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...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.