Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / December 2004

Tip: Looking for answers? Try searching our database.

Drag form w/out controlbox

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ryan Joseph So - 07 Dec 2004 18:10 GMT
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.
Peter Jausovec - 07 Dec 2004 18:40 GMT
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;
   }
}

Signature

Regards,
Peter Jausovec
(http://blog.jausovec.net)

> Hi,
> I have a form which the formborderstyle was set to none hiding the
[quoted text clipped - 7 lines]
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!
Ryan Joseph So - 08 Dec 2004 14:50 GMT
Thank you very much for the quick post. I'll try your codes immediately.
Herfried K. Wagner [MVP] - 07 Dec 2004 23:06 GMT
"Ryan Joseph So" <achilles_ryan@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>

Signature

M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://dotnet.mvps.org/dotnet/faqs/

Mike in Paradise - 07 Dec 2004 23:21 GMT
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);
}
}
}

> Hi,
> I have a form which the formborderstyle was set to none hiding the
[quoted text clipped - 7 lines]
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.