473,385 Members | 1,642 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,385 software developers and data experts.

Custom form drag, does not work... why?

Hi,
I have a borderless form and I try to drag it. When I do it, the form start
to jump from position to position even when I don't move the mouse... My
formula seems right, but the result is not... can somebody help me please?

here is the code:

private void managementConsoleBarSmall1_MouseDown(object sender,
MouseEventArgs e)
{
if (!m_Dragging)
{
m_InitialDragPoint = new Point(e.X, e.Y);
}
m_Dragging = true;
}
private void managementConsoleBarSmall1_MouseUp(object sender,
MouseEventArgs e)
{
m_Dragging = false;
}
private void managementConsoleBarSmall1_MouseMove(object sender,
MouseEventArgs e)
{
if (m_Dragging)
{
this.SetBounds(this.Left + (e.X - m_InitialDragPoint.X), this.Top +
(e.Y - m_InitialDragPoint.Y), this.Width, this.Height);
this.m_InitialDragPoint = new Point(e.X, e.Y);
System.Threading.Thread.Sleep(10);
}
}

Someone sees something wrong here?

thanks

ThunderMusic
Jul 14 '06 #1
4 1721
if it can be of any use, I'm on VS2005, so framework 2.0

"ThunderMusic" <No*************************@NoSpAm.comwrote in message
news:ue****************@TK2MSFTNGP03.phx.gbl...
Hi,
I have a borderless form and I try to drag it. When I do it, the form
start to jump from position to position even when I don't move the
mouse... My formula seems right, but the result is not... can somebody
help me please?

here is the code:

private void managementConsoleBarSmall1_MouseDown(object sender,
MouseEventArgs e)
{
if (!m_Dragging)
{
m_InitialDragPoint = new Point(e.X, e.Y);
}
m_Dragging = true;
}
private void managementConsoleBarSmall1_MouseUp(object sender,
MouseEventArgs e)
{
m_Dragging = false;
}
private void managementConsoleBarSmall1_MouseMove(object sender,
MouseEventArgs e)
{
if (m_Dragging)
{
this.SetBounds(this.Left + (e.X - m_InitialDragPoint.X), this.Top +
(e.Y - m_InitialDragPoint.Y), this.Width, this.Height);
this.m_InitialDragPoint = new Point(e.X, e.Y);
System.Threading.Thread.Sleep(10);
}
}

Someone sees something wrong here?

thanks

ThunderMusic

Jul 14 '06 #2
ThunderMusic wrote:
Hi,
I have a borderless form and I try to drag it. When I do it, the form start
to jump from position to position even when I don't move the mouse... My
formula seems right, but the result is not... can somebody help me please?
I don't know why your code is behaving the way it is, but try this code
in your form:

protected override void WndProc(ref Message m)
{
const int WmNcHitTest = 0x84;
const int HtCaption = 2;

if (m.Msg == WmNcHitTest)
m.Result = new IntPtr(HtCaption);
else
base.WndProc(ref m);
}

With the code above you can click anywhere of the form and move the
form.

If you have panels or other controls on the form and you want to move
the form by clicking on them you can use this code (uses a panel but
should work on other controls):

private void pnlAdmin_MouseDown(object sender, MouseEventArgs
e)
{
const uint WM_SYSCOMMAND = 0x0112;
const uint SC_MOVE = 0xF010;
const int HtCaption = 2;

pnlAdmin.Capture = false;

SendMessage(this.Handle, WM_SYSCOMMAND, new IntPtr(SC_MOVE
+ HtCaption),new IntPtr(0));
}

Hope this helps

Jul 14 '06 #3

ThunderMusic wrote:
Hi,
I have a borderless form and I try to drag it. When I do it, the form start
to jump from position to position even when I don't move the mouse... My
formula seems right, but the result is not... can somebody help me please?

here is the code:

private void managementConsoleBarSmall1_MouseDown(object sender,
MouseEventArgs e)
{
if (!m_Dragging)
{
m_InitialDragPoint = new Point(e.X, e.Y);
}
m_Dragging = true;
}
private void managementConsoleBarSmall1_MouseUp(object sender,
MouseEventArgs e)
{
m_Dragging = false;
}
private void managementConsoleBarSmall1_MouseMove(object sender,
MouseEventArgs e)
{
if (m_Dragging)
{
this.SetBounds(this.Left + (e.X - m_InitialDragPoint.X), this.Top +
(e.Y - m_InitialDragPoint.Y), this.Width, this.Height);
this.m_InitialDragPoint = new Point(e.X, e.Y);
System.Threading.Thread.Sleep(10);
}
}

Someone sees something wrong here?
Quite an entertaining effect, but clearly not what you want. I think
your problems stem from confusion between the two different kinds of
coordinates - *client* coordinates (relative to a control, so (0,0) is
the top left corner) and *screen* coordinates.

This is one way to fix your code:

- Get rid of m_InitialDragPoint, and have a new Point variable called
m_DragPointOffset.
- Change the MouseDown routine to:

{
if (!m_Dragging)
{
// Remember the offset between the point of mousedown
// and the top left of the form
// Note that MouseEeventArgs.X and .Y are *client*
// coordinates, so they are already the numbers we want
m_DragPointOffset = new Point(e.X, e.Y);

m_Dragging = true;
}
}

- Change the MouseMove routine to:

{
if (m_Dragging)
{
// Move the form. We want to move the form to such
// a place that e.Location is the same as
m_DragPointOffset
// (that is, the mouse pointer is at the same relative
// location as when the mouse button was pressed).
// So we do this:
this.SetBounds(this.Left + e.X - m_DragPointOffset.X,
this.Top + e.Y - m_DragPointOffset.Y,
this.Width,
this.Height);

// Note that moving the form will trigger another
// MouseMove, but because the above calculation will
then
// result in the form not moving, we *don't* need
anything
// like this:
//System.Threading.Thread.Sleep(10);
}

}

Note that the way some people implement dragging of borderless forms is
by overriding the WndProc and converting mousedowns to mousedowns in
the caption area. I don't know which way is better, or why.

--
Larry Lard
Replies to group please

Jul 14 '06 #4
Thanks a lot... it works perfectly!! I don't see such a big change, but it
works so that perfect!! Thanks again...
"Larry Lard" <la*******@hotmail.comwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
>
ThunderMusic wrote:
>Hi,
I have a borderless form and I try to drag it. When I do it, the form
start
to jump from position to position even when I don't move the mouse... My
formula seems right, but the result is not... can somebody help me
please?

here is the code:

private void managementConsoleBarSmall1_MouseDown(object sender,
MouseEventArgs e)
{
if (!m_Dragging)
{
m_InitialDragPoint = new Point(e.X, e.Y);
}
m_Dragging = true;
}
private void managementConsoleBarSmall1_MouseUp(object sender,
MouseEventArgs e)
{
m_Dragging = false;
}
private void managementConsoleBarSmall1_MouseMove(object sender,
MouseEventArgs e)
{
if (m_Dragging)
{
this.SetBounds(this.Left + (e.X - m_InitialDragPoint.X), this.Top
+
(e.Y - m_InitialDragPoint.Y), this.Width, this.Height);
this.m_InitialDragPoint = new Point(e.X, e.Y);
System.Threading.Thread.Sleep(10);
}
}

Someone sees something wrong here?

Quite an entertaining effect, but clearly not what you want. I think
your problems stem from confusion between the two different kinds of
coordinates - *client* coordinates (relative to a control, so (0,0) is
the top left corner) and *screen* coordinates.

This is one way to fix your code:

- Get rid of m_InitialDragPoint, and have a new Point variable called
m_DragPointOffset.
- Change the MouseDown routine to:

{
if (!m_Dragging)
{
// Remember the offset between the point of mousedown
// and the top left of the form
// Note that MouseEeventArgs.X and .Y are *client*
// coordinates, so they are already the numbers we want
m_DragPointOffset = new Point(e.X, e.Y);

m_Dragging = true;
}
}

- Change the MouseMove routine to:

{
if (m_Dragging)
{
// Move the form. We want to move the form to such
// a place that e.Location is the same as
m_DragPointOffset
// (that is, the mouse pointer is at the same relative
// location as when the mouse button was pressed).
// So we do this:
this.SetBounds(this.Left + e.X - m_DragPointOffset.X,
this.Top + e.Y - m_DragPointOffset.Y,
this.Width,
this.Height);

// Note that moving the form will trigger another
// MouseMove, but because the above calculation will
then
// result in the form not moving, we *don't* need
anything
// like this:
//System.Threading.Thread.Sleep(10);
}

}

Note that the way some people implement dragging of borderless forms is
by overriding the WndProc and converting mousedowns to mousedowns in
the caption area. I don't know which way is better, or why.

--
Larry Lard
Replies to group please

Jul 14 '06 #5

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

Similar topics

3
by: Kyle Fitzgerald | last post by:
I've started a web control library project and can build my own controls to add to the toolbox in the .NET environment. The problem I'm having is I want to create a control just like the HTML...
1
by: Michael Skelton | last post by:
Hi I've created a new custom Web control. I have tried to customize the assembly attribute TagPrefix . However, each time I drag my custom control onto a form, it's TagPrefix is still "cc1". What...
3
by: Michael | last post by:
Hi all.. I have a solution containing 5 projects, one of which is a custom control. In one of the projects, I dragged the .ascx file from the custom control project and dropped it onto a form....
2
by: Suzanne | last post by:
Hi all, I'm reposting this message as I'm experiencing this problem more and more frequently : I really hope someone out there can help me as I've been tearing my hair out on this one for a...
2
by: Tony Hedge | last post by:
Hello, Framework: NET 1.1, Language VB So I am going through the basic walkthrough example in .NET on how to create a simple custom control. Takes about 2 minutes and when done I have a DLL...
15
by: rizwanahmed24 | last post by:
Hello i have made a custom control. i have placed a panel on it. I want this panel to behave just like the normal panel. The problem i was having is that the panel on my custom control doesnt...
3
by: moondaddy | last post by:
I have a windows WPF sample project which is starting to work pretty good. I can drag shapes and lines, and connect a straight line to any place on a custom rectangle shape's boarder. Now I have a...
3
by: Claes Wedin | last post by:
I'm doing a Component class that inherits from DataGridView. One thing that it does is to add a default column in the grid. I put the code for this in the class and when I drag the control to my...
9
by: Gord | last post by:
In VB6, a custom dialog can be easily created by adding a new form, adding whatever controls you like, sizing it as you like, adding code and then just loading/unloading it whenever you like....
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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...

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.