Page 1 of 1

Macro - Draggable borderless form.

PostPosted: Mon Apr 16, 2018 2:07 pm
by kig23
Here is an example of how to create draggable borderless form.

Code: Select all
Button myButton = new Button ();
myButton.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(211)))), ((int)(((byte)(87)))), ((int)(((byte)(40)))));
myButton.FlatAppearance.BorderSize = 0;
myButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
myButton.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(40)))), ((int)(((byte)(52)))), ((int)(((byte)(63)))));
myButton.Location = new System.Drawing.Point(105, 197);
myButton.Size = new System.Drawing.Size(75, 23);
myButton.TabIndex = 0;
myButton.Text = "Close";
myButton.UseVisualStyleBackColor = false;
myButton.Click += new System.EventHandler(myButton_Click);

myForm = new Form ();
myForm.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(52)))), ((int)(((byte)(73)))), ((int)(((byte)(94)))));
myForm.ClientSize = new System.Drawing.Size(284, 261);
myForm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
myForm.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
myForm.MouseDown += new System.Windows.Forms.MouseEventHandler(myForm_MouseDown);
myForm.MouseMove += new System.Windows.Forms.MouseEventHandler(myForm_MouseMove);
myForm.Controls.Add(myButton);
myForm.ResumeLayout(false);
myForm.BringToFront();
myForm.ShowDialog (exec.mainform);

#Events

Form myForm;

public Point mouseLocation;

private void myForm_MouseDown(object sender, MouseEventArgs e)
{
   mouseLocation = new Point(-e.X, -e.Y);
}

private void myForm_MouseMove(object sender, MouseEventArgs e)
{
   if (e.Button == MouseButtons.Left)
   {
      Point mousePos = Control.MousePosition;
      mousePos.Offset(mouseLocation.X, mouseLocation.Y);
      myForm.Location = mousePos;
   }
}

private void myButton_Click(object sender, EventArgs e)
{
   myForm.Close();
}

Re: Macro - Draggable borderless form.

PostPosted: Mon Apr 16, 2018 3:27 pm
by kig23
You're welcome.