[Tutorial] Move a borderless form menu

Shout-Out

User Tag List

Results 1 to 7 of 7
  1. #1
    Mr.Zunz's Avatar Contributor
    Reputation
    92
    Join Date
    Mar 2007
    Posts
    393
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [Tutorial] Move a borderless form

    Heyho, here's an example of what i used in my application to move a borderless form.

    Put this pointer and a bool outside any event:
    Code:
    private Point LastCursorPosition;
    private bool IsMouseDown;
    Example
    Code:
            private Point LastCursorPosition;
            private bool IsMouseDown;
    
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                // Do something
            }

    Put this in your Form1_MouseDown event.
    Code:
    this.IsMouseDown = true;
    this.LastCursorPosition = new Point(e.X, e.Y);
    Put this in your Form1_MouseUp event.
    Code:
    this.IsMouseDown = false;
    put this in your Form1_MouseMove event
    Code:
    if (this.IsMouseDown == true)
                {
                    //Move the form
                    this.Location = new Point(this.Left - (this.LastCursorPosition.X - e.X), this.Top - (this.LastCursorPosition.Y - e.Y));
    
                    //Redraw the form//
                    this.Invalidate();
                }
    That's it! it's simple
    Last edited by WinRawr; 05-08-2009 at 03:45 PM.


    [Tutorial] Move a borderless form
  2. #2
    lanman92's Avatar Active Member
    Reputation
    50
    Join Date
    Mar 2007
    Posts
    1,033
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm pretty sure I saw this on CodeProject or something. It's a cool idea, and idk if you took it from there. Kind of common sense, but w/e. I might put it to use sometime.

  3. #3
    Nesox's Avatar ★ Elder ★
    Reputation
    1280
    Join Date
    Mar 2007
    Posts
    1,238
    Thanks G/R
    0/3
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can do it like this too:

    Code:
    using System;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
    using System.Threading;
    using Magic;
    using System.Diagnostics;
    using BlueBox;
    
    namespace ConsoleGUI
    {
        public partial class frmMain : Form
        {
            #region Form Dragging API Support
    
            //The SendMessage function sends a message to a window or windows. 
            [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
            static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);
    
            //ReleaseCapture releases a mouse capture
            [DllImportAttribute("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
            public static extern bool ReleaseCapture();
    
            #endregion
    
            public frmMain()
            {
                InitializeComponent();
            }
    
            #region Moving the form around
    
            private void textBox_console_MouseDown(object sender, MouseEventArgs e)
            {
                if (e.Button == MouseButtons.Left)
                {
                    ReleaseCapture();
                    SendMessage(Handle, 0xA1, 0x2, 0);
                }
            }
    
            private void frmMain_MouseDown(object sender, MouseEventArgs e)
            {
                if (e.Button == MouseButtons.Left)
                {
                    ReleaseCapture();
                    SendMessage(Handle, 0xa1, 0x2, 0);
                }
            }
    
            #endregion
    
           
        }
    }

  4. #4
    visitor's Avatar Contributor
    Reputation
    174
    Join Date
    Mar 2008
    Posts
    307
    Thanks G/R
    16/15
    Trade Feedback
    1 (100%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    if (this.IsMouseDown == true)
    8 characters not needed: " == true".
    Hey I just met you

  5. #5
    dekz's Avatar Member
    Reputation
    5
    Join Date
    Jan 2008
    Posts
    37
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    pointer
    what pointer

  6. #6
    Robske's Avatar Contributor
    Reputation
    305
    Join Date
    May 2007
    Posts
    1,062
    Thanks G/R
    3/4
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    WPF users can do the following:

    Add this line to your XAML:
    Code:
    <Window x:Class="PCynder.WindowHome"  MouseLeftButtonDown="WindowHome_MouseLeftButtonDown">
            Window components, resources, templates etc come here
    </window>
    Then add the following to your code:
    Code:
    /// <summary>
    /// Allow Dragging of a borderless window.
    /// </summary>
    private void WindowHome_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
          if (e.LeftButton == MouseButtonState.Pressed)
                    this.DragMove();
    }
    Now try doing it in JAVALOL
    Last edited by Robske; 05-15-2009 at 06:23 AM.
    "Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - Martin Golding
    "I cried a little earlier when I had to poop" - Sku

  7. #7
    Mr.Zunz's Avatar Contributor
    Reputation
    92
    Join Date
    Mar 2007
    Posts
    393
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by lanman92 View Post
    I'm pretty sure I saw this on CodeProject or something. It's a cool idea, and idk if you took it from there. Kind of common sense, but w/e. I might put it to use sometime.
    Yeah I did copypasta it from my own source, and im 95% sure i got it form codeproject so, Yup. I thought I just wanted to share it on here. I'm not taking credits for it tho. :wave:
    Last edited by WinRawr; 05-15-2009 at 04:03 PM.


Similar Threads

  1. Replies: 24
    Last Post: 02-21-2014, 12:41 PM
  2. [Tutorial] jQuery - Wicked form validation
    By Sirupsen in forum Programming
    Replies: 0
    Last Post: 04-09-2009, 07:33 AM
  3. Game Hacking Tutorial!
    By lopolop in forum Community Chat
    Replies: 24
    Last Post: 06-29-2006, 08:39 AM
  4. Skeletal Form and Mounted
    By Matt in forum World of Warcraft Exploits
    Replies: 1
    Last Post: 04-17-2006, 05:09 AM
  5. MMOwned's Server Move + Forum Change
    By Matt in forum OC News
    Replies: 0
    Last Post: 03-25-2006, 04:52 AM
All times are GMT -5. The time now is 06:40 AM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search