常用代码

  try
            {


                DialogResult AuthenticationDialog = MessageBox.Show("您是否要退出软件?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information); 
                switch (AuthenticationDialog)
                {
                    case System.Windows.Forms.DialogResult.Yes:
                        e.Cancel = false;
                        this.notifyIcon1.Dispose();
                        break;
                    default:
                        e.Cancel = true;
                        break;

                }
            }
            catch
            {
                e.Cancel = true;
            }
dgv.RowsDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;居中
  this.BeginInvoke((MethodInvoker)delegate()
                {
                    UserInfo _UserInfo = new UserInfo();
                    _UserInfo.Show();
                });
原文地址:https://www.cnblogs.com/wangchuang/p/5123973.html