相关疑难解决方法(0)

FormStartPosition.CenterParent不起作用

在下面的代码中,只有第二种方法适用于我(.NET 4.0).FormStartPosition.CenterParent不会将子表单置于其父表单的中心.为什么?

资料来源:这个问题

using System;
using System.Drawing;
using System.Windows.Forms;

class Program
{
  private static Form f1;

  public static void Main()
  {
    f1 = new Form() { Width = 640, Height = 480 };
    f1.MouseClick += f1_MouseClick; 
    Application.Run(f1);
  }

  static void f1_MouseClick(object sender, MouseEventArgs e)
  {
    Form f2 = new Form() { Width = 400, Height = 300 };
    switch (e.Button)
    {
      case MouseButtons.Left:
      {
        // 1st method
        f2.StartPosition = FormStartPosition.CenterParent;
        break;
      }
      case MouseButtons.Right:
      {
        // 2nd …
Run Code Online (Sandbox Code Playgroud)

c# forms parent-child winforms centering

32
推荐指数
5
解决办法
3万
查看次数

标签 统计

c# ×1

centering ×1

forms ×1

parent-child ×1

winforms ×1