How to move a form to center position
Just set the form's StartPosition property to CenterScreen.
using System.Windows.Forms;
using System;
using System.Drawing;
namespace WindowsFormsApplication
{
public partial class Form : Form
{
public Form()
{
InitializeComponent();
this.StartPosition = FormStartPosition.CenterScreen;
}
private void Center(Form form)
{
form.Location = new Point(
(Screen.PrimaryScreen.Bounds.Size.Width / 2) - (form.Size.Width / 2),
(Screen.PrimaryScreen.Bounds.Size.Height / 2) - (form.Size.Height / 2));
}
private void button_Click(object sender, EventArgs e)
{
Center(this);
}
}
}
Reference : Move a form to center position
Written by 小叮噹文青
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#.net
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#