Home All Groups Group Topic Archive Search About
Author
7 Dec 2004 6:10 PM
Ryan Joseph So
Hi,
I have a form which the formborderstyle was set to none hiding the
controlbox. My problem is I can't reposition the form on the screen by
using my mouse when I run the application because it has no controlbox.
Is it possible to drag the form to other location on the screen without
the controlbox? How? Thanks in advance.

Ryan.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Author
7 Dec 2004 6:40 PM
Peter Jausovec
Hi,

I use this code:

private Point mouseOffset;
private bool isMouseDown = false;

private void frm_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
int xOffset;
int yOffset;
    if (e.Button == MouseButtons.Left)
    {
    xOffset = -e.X - SystemInformation.FrameBorderSize.Width;
    yOffset = -e.Y -
SystemInformation.CaptionHeight -SystemInformation.FrameBorderSize.Height;

    mouseOffset = new Point(xOffset, yOffset);
    isMouseDown = true;
    }
}
private void frm_MouseMove(object sender,
System.Windows.Forms.MouseEventArgs e)
{
    if (isMouseDown)
    {
        Point mousePos = Control.MousePosition;
        mousePos.Offset(mouseOffset.X, mouseOffset.Y);
        Location = mousePos;
    }
}

private void FrmGlavna_MouseUp(object sender,
System.Windows.Forms.MouseEventArgs e)
{
    if (e.Button == MouseButtons.Left)
    {
        isMouseDown = false;
    }
}


--
Regards,
Peter Jausovec
(http://blog.jausovec.net)
Show quoteHide quote
"Ryan Joseph So" <achilles_r***@hotmail.com> je napisal v sporocilo
news:OmYu9fI3EHA.2624@TK2MSFTNGP11.phx.gbl ...
> Hi,
> I have a form which the formborderstyle was set to none hiding the
> controlbox. My problem is I can't reposition the form on the screen by
> using my mouse when I run the application because it has no controlbox.
> Is it possible to drag the form to other location on the screen without
> the controlbox? How? Thanks in advance.
>
> Ryan.
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!
Are all your drivers up to date? click for free checkup

Author
8 Dec 2004 2:50 PM
Ryan Joseph So
Thank you very much for the quick post. I'll try your codes immediately.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Author
7 Dec 2004 11:06 PM
Herfried K. Wagner [MVP]
"Ryan Joseph So" <achilles_r***@hotmail.com> schrieb:
> I have a form which the formborderstyle was set to none hiding the
> controlbox. My problem is I can't reposition the form on the screen by
> using my mouse when I run the application because it has no controlbox.
> Is it possible to drag the form to other location on the screen without
> the controlbox?

<URL:http://groups.google.de/groups?selm=eGxfP4aZEHA.3016%40tk2msftngp13.phx.gbl>

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>
Author
7 Dec 2004 11:21 PM
Mike in Paradise
I use this class...

when I want to Move a Form.
..
Eg on a mouse click..

Win32API.SendMessage_MouseDownInCaption( form)


//*********** Win32App*****************
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Drawing;

namespace Bon
{
/// <summary>
/// Static Methods and Constants to inferface with Win32API.
/// </summary>
public class Win32API
{
static Win32API()
{
}
/// <summary>
/// Method: Release capturing of Mouse Events..
/// </summary>
/// <returns></returns>
[DllImport("User32.dll")]
public static extern bool ReleaseCapture(); 

/// <summary>
/// Method: Access to the Win32 SendMessage API
/// </summary>
/// <param name="hWnd"></param>
/// <param name="msg"></param>
/// <param name="wParam"></param>
/// <param name="lParam"></param>
/// <returns></returns>
[DllImport("user32.dll", CharSet=CharSet.Auto)]
extern public static IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam,
IntPtr lParam) ;
/// <summary>
/// Send a WM_MOUSELEAVE manually to a window.
/// </summary>
/// <param name="hWnd"></param>
public static void SendMessage_WM_MOUSELEAVE(IntPtr hWnd)
{
    SendMessage(hWnd,(int)WM_Message.WM_MOUSELEAVE, IntPtr.Zero, IntPtr.Zero);
}
/// <summary>
/// Sends Form a Message (WM_NCLBUTTONDOWN) that it is in Caption so form is
in
/// Move mode..
/// </summary>
/// <param name="form"></param>
public static void SendMessage_MouseDownInCaption(Form form)
{   
    if (form != null)
    {
        const int WM_NCLBUTTONDOWN = 0x00A1;
        const int HTCAPTION = 2;
        //Position cursor inside current Caption
        Point locationOnScreen = form.Location;
        if (form.Parent != null)
        {
            locationOnScreen = form.Parent.PointToScreen(form.Location);
        }
        Point pointInCaption =
            new Point( locationOnScreen.X + 4, locationOnScreen.Y + 4 );
        ReleaseCapture();
        IntPtr lParam = GetLParam(pointInCaption);
        Cursor.Position = pointInCaption;
        Application.DoEvents();
        SendMessage(form.Handle, WM_NCLBUTTONDOWN ,(IntPtr)HTCAPTION, lParam);
    }
}
/// <summary>
/// Static Method: Returns a Long from a lowWord and HiWord Integer
/// </summary>
/// <param name="LoWord"></param>
/// <param name="HiWord"></param>
/// <returns></returns>
public static int GetLong(int loWord, int hiWord)
{
    return (hiWord << 16) | (loWord & 0xffff);
}
/// <summary>
/// Return a LParam structure pointer from a LoWord and HiWord
/// </summary>
/// <param name="LoWord"></param>
/// <param name="HiWord"></param>
/// <returns></returns>
public static IntPtr GetLParam(int loWord, int hiWord)
{
    return (IntPtr) ((hiWord << 16) | (loWord & 0xffff));
}
/// <summary>
/// Return a LParam structure pointer from Point
/// </summary>
/// <param name="LoWord"></param>
/// <param name="HiWord"></param>
/// <returns></returns>
public static IntPtr GetLParam(Point point)
{
    return (IntPtr) ((point.X << 16) | (point.Y & 0xffff));
}        /// <summary>
/// Method: Lets the HiWord from an integer value, good for interpreting
/// LParam, WParam etc
/// </summary>
/// <param name="aValue"></param>
/// <returns></returns>
public static int GetHiWord(int aValue)
{
    return (short)(((uint)aValue & 0xFFFF0000U) >> 16);
}
/// <summary>
/// Method: Lets the LoWord from an integer value, good for interpreting
/// LParam, WParam etc
/// </summary>
/// <param name="aValue"></param>
/// <returns></returns>
public static int GetLoWord(int aValue)
{
    //return aValue & 0xffff;
    return (short)((uint)aValue & 0x0000FFFFU);
}
}
}

Show quoteHide quote
"Ryan Joseph So" wrote:

> Hi,
> I have a form which the formborderstyle was set to none hiding the
> controlbox. My problem is I can't reposition the form on the screen by
> using my mouse when I run the application because it has no controlbox.
> Is it possible to drag the form to other location on the screen without
> the controlbox? How? Thanks in advance.
>
> Ryan.
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!
>

Bookmark and Share