Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. drag window wothout titlebar

drag window wothout titlebar

Scheduled Pinned Locked Moved C#
question
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    troels_sorensen
    wrote on last edited by
    #1

    Hi. How do i drag and move a window using the mouse, when the window do not have a titlebar??? I thought of using MouseDown, MouseMove and MouseUp to move it, but i can't seem to get it to work :-( As their an easier way??

    A A 2 Replies Last reply
    0
    • T troels_sorensen

      Hi. How do i drag and move a window using the mouse, when the window do not have a titlebar??? I thought of using MouseDown, MouseMove and MouseUp to move it, but i can't seem to get it to work :-( As their an easier way??

      A Offline
      A Offline
      Amirjalaly
      wrote on last edited by
      #2

      may be this code can help you add mousemove event and form_load event to your form and three variables x,y,click,first to your class check this code is true or not. private int x,y; bool click=false; bool first=false; private void Form1_MouseMove(object sender,System.Windows.Forms.MouseEventArgs e) { if(e.Button==MouseButtons.Left) { if(click&&first) this.Location=new Point(this.Location.X+e.X- x,this.Location.Y+e.Y-y); x=e.X; y=e.Y; click=true; first=!first; } else click=false; } private void Form1_Load(object sender, System.EventArgs e) { x=this.Location.X; y=this.Location.Y; }

      T 1 Reply Last reply
      0
      • T troels_sorensen

        Hi. How do i drag and move a window using the mouse, when the window do not have a titlebar??? I thought of using MouseDown, MouseMove and MouseUp to move it, but i can't seem to get it to work :-( As their an easier way??

        A Offline
        A Offline
        Alvaro Mendez
        wrote on last edited by
        #3

        Back in the days of MFC, this was as simple as adding a handler for the WM_NCHITTEST (0x0084) message and returning HTCAPTION (2). I just tried doing the equivalent of that on a C# project of mine but it didn't work! :confused:

        protected override void WndProc(ref Message m)
        {
        if (m.Msg == 0x0084)
        m.Result = (IntPtr)2;
        base.WndProc(ref m);
        }

        What's also weird is that m.Result always comes in with a value of 0, no matter where I place the cursor on the form. :sigh: By the way, how did you create a form without a titlebar? Regards, Alvaro


        He who laughs last, thinks slowest.

        J 1 Reply Last reply
        0
        • A Alvaro Mendez

          Back in the days of MFC, this was as simple as adding a handler for the WM_NCHITTEST (0x0084) message and returning HTCAPTION (2). I just tried doing the equivalent of that on a C# project of mine but it didn't work! :confused:

          protected override void WndProc(ref Message m)
          {
          if (m.Msg == 0x0084)
          m.Result = (IntPtr)2;
          base.WndProc(ref m);
          }

          What's also weird is that m.Result always comes in with a value of 0, no matter where I place the cursor on the form. :sigh: By the way, how did you create a form without a titlebar? Regards, Alvaro


          He who laughs last, thinks slowest.

          J Offline
          J Offline
          Judah Gabriel Himango
          wrote on last edited by
          #4

          I think I've seen someone doing it in C# using Windows message processing like you show... Forms can be created without titlebars via myForm.FormBorderStyle = FormBorderStyle.None The graveyards are filled with indispensible men.

          1 Reply Last reply
          0
          • A Amirjalaly

            may be this code can help you add mousemove event and form_load event to your form and three variables x,y,click,first to your class check this code is true or not. private int x,y; bool click=false; bool first=false; private void Form1_MouseMove(object sender,System.Windows.Forms.MouseEventArgs e) { if(e.Button==MouseButtons.Left) { if(click&&first) this.Location=new Point(this.Location.X+e.X- x,this.Location.Y+e.Y-y); x=e.X; y=e.Y; click=true; first=!first; } else click=false; } private void Form1_Load(object sender, System.EventArgs e) { x=this.Location.X; y=this.Location.Y; }

            T Offline
            T Offline
            troels_sorensen
            wrote on last edited by
            #5

            Great! that was exatly what i needed! thanks a bunch.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups