How to move form without form border (visual studio)

后端 未结 9 2019
无人共我
无人共我 2020-12-09 13:38

I am making a windows form application in visual studio 2013 Express. In order to make the application look more customized and attractive, I designed the forms in my applic

9条回答
  •  时光说笑
    2020-12-09 13:47

    a late answer but there is an alternative we can use example you have a form lets name it Form1

    In Design View

    • do not hide the border from the property menu do it in code
    namespace Project
    {
        public partial class Form1: Form
        {
                InitializeComponent();
                 this.DoubleBuffered = true; //disable flickers
                this.Text = string.Empty;
                this.ControlBox = false;
                this.MaximizedBounds = Screen.FromHandle(this.Handle).WorkingArea;
        }
    
      //Drag Form
            [DllImport("user32.DLL", EntryPoint = "ReleaseCapture")]
            private extern static void ReleaseCapture();
            [DllImport("user32.DLL", EntryPoint = "SendMessage")]
    
            private extern static void SendMessage(System.IntPtr hWnd, int wMsg, int wParam, int lParam);
    //mousedown on where ever u wanna use the moving of form function in
      private void topPanel_MouseDown(object sender, MouseEventArgs e)
            {
                ReleaseCapture();
                SendMessage(this.Handle, 0x112, 0xf012, 0);
            }
    }
    

    now when you will run the code your form will look something like this:

    when application is executed

    now when u hold down your mouse at the pink bar and drag it around it should work.

提交回复
热议问题