3

Winformsアプリケーションのウィンドウの場所に関して問題があります。

起動時にウィンドウを画面の中央に配置する必要があります。次のことを試しましたが、うまくいきませんでした。フォームは常に左上隅に開きます。

loadイベントでこれらを試しました:

this.CenterToScreen();
this.Location = new Point((Screen.PrimaryScreen.WorkingArea.Width - this.Width) / 2,
                          (Screen.PrimaryScreen.WorkingArea.Height - this.Height) / 2);

更新:フォームの最大サイズと最小サイズを1090,726として指定しました。

私のデザイナーファイルには次のコードがあります:

        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.BackColor = System.Drawing.SystemColors.GrayText;
        this.ClientSize = new System.Drawing.Size(1074, 688);
        this.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
        this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
        this.MaximizeBox = false;
        this.MaximumSize = new System.Drawing.Size(1090, 726);
        this.MinimumSize = new System.Drawing.Size(1090, 726);
        this.Name = "Mail_Remainder";
        this.RightToLeftLayout = true;
        this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
        this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
        this.Text = "Remainder";
        this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
        this.Load += new System.EventHandler(this.Mail_Remainder_Load);
        this.Resize += new System.EventHandler(this.Mail_Remainder_Resize);
        this.ResumeLayout(false);
        this.PerformLayout();

これを行う他の方法はありますか?

助けてください。

4

3 に答える 3

7

以下を見てください。

 Form1.StartPosition = FormStartPosition.CenterScreen;
 Form1.Show();

編集:

この線

 this.WindowState = System.Windows.Forms.FormWindowState.Maximized;

偏心を引き起こしているものです。

コメントした場合:

    private void InitializeComponent()
    {
        this.SuspendLayout();
        // 
        // Form1
        // 
                    this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.BackColor = System.Drawing.SystemColors.GrayText;
        this.ClientSize = new System.Drawing.Size(1074, 688);
        this.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
        this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
        this.MaximizeBox = false;
        this.MaximumSize = new System.Drawing.Size(1090, 726);
        this.MinimumSize = new System.Drawing.Size(1090, 726);
        this.Name = "Mail_Remainder";
        this.RightToLeftLayout = true;
        this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
        this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
        this.Text = "Remainder";
//            this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
        this.Load += new System.EventHandler(this.Mail_Remainder_Load);
        this.Resize += new System.EventHandler(this.Mail_Remainder_Resize);
        this.ResumeLayout(false);
        this.PerformLayout();

    }

画面の中央にウィンドウが表示されます。

于 2012-11-22T10:27:56.407 に答える
4

StartPositionフォームのプロパティをCenterScreen....に設定するだけです。

ここに画像の説明を入力してください

于 2012-11-22T10:28:29.807 に答える
1

私も同様の問題を抱えていました。CenterToScreen()の後、フォームは中心から外れていました。次に、InitializeComponent()の前にこれを実行していることに気付きました。InitializeComponentの後に移動しましたが、正常に機能しました。

于 2016-06-02T19:55:41.890 に答える