C♯相談室 Part15
■ このスレッドは過去ログ倉庫に格納されています
0218デフォルトの名無しさん
NGNGWindowsフォームを表示する際に画面の中央に表示させたいのですが、
どうもうまくいきません。いろいろ試行錯誤したソースが以下です。
なにがおかしいのでしょうか。記述はFormのInitializeComponent関数の
後ろにしています。
Rectangle tempRectangle1 = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea;
Rectangle tempRectangle2 = this.Bounds;
this.label2.Text = System.Convert.ToString(tempRectangle1.Width)
+ "," + System.Convert.ToString(tempRectangle1.Height);
this.label3.Text = System.Convert.ToString(tempRectangle2.Width)
+ "," + System.Convert.ToString(tempRectangle2.Height);
//this.label2.Text = System.Convert.ToString(System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width);
//this.label3.Text = System.Convert.ToString(System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height);
//this.DesktopLocation.X = (tempRectangle.Width - tempRectangle2.Width) / 2;
//this.DesktopLocation.Y = (tempRectangle.Height - tempRectangle2.Height) / 2;
//this.label2.Text = this.DesktopLocation.ToString();
//this.DesktopLocation = new Point((tempRectangle1.Width - tempRectangle2.Width) / 2, (tempRectangle1.Height - tempRectangle2.Height) / 2);
//this.label3.Text = this.DesktopLocation.ToString();
//this.Location = new Point((tempRectangle1.Width - tempRectangle2.Width) / 2, (tempRectangle1.Height - tempRectangle2.Height) / 2);
this.Text = "Hello,World";
this.Top = (tempRectangle1.Width - tempRectangle2.Width) / 2;
this.Left = (tempRectangle1.Height - tempRectangle2.Height) / 2;
■ このスレッドは過去ログ倉庫に格納されています