PC Review


Reply
Thread Tools Rate Thread

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

 
 
ThunderMusic
Guest
Posts: n/a
 
      14th Jul 2006
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


 
Reply With Quote
 
 
 
 
ThunderMusic
Guest
Posts: n/a
 
      14th Jul 2006
if it can be of any use, I'm on VS2005, so framework 2.0

"ThunderMusic" <(E-Mail Removed)> wrote in message
news:uev6u%(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
Chris Dunaway
Guest
Posts: n/a
 
      14th Jul 2006
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

 
Reply With Quote
 
Larry Lard
Guest
Posts: n/a
 
      14th Jul 2006

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

 
Reply With Quote
 
ThunderMusic
Guest
Posts: n/a
 
      14th Jul 2006
Thanks a lot... it works perfectly!! I don't see such a big change, but it
works so that perfect!! Thanks again...


"Larry Lard" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> 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
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Drag on Drop from email message to custom form - no attachment Matt Microsoft Outlook Form Programming 1 18th Mar 2008 04:39 PM
Problem with custom form after drag and drop (security related?) =?Utf-8?B?QWxhbkdsb3Zlcg==?= Microsoft Outlook Form Programming 3 15th Nov 2007 05:41 PM
Custom form drag, does not work... why? ThunderMusic Microsoft Dot NET Framework Forms 4 14th Jul 2006 04:13 PM
Custom popup form on drag'n'drop files to folder medium1983@mail.ru Microsoft Outlook Form Programming 0 12th Jul 2006 07:11 AM
drag and drop data from standard form into custom form? +@itude Microsoft Outlook Contacts 1 1st Jul 2005 06:19 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:18 PM.