c# -如何设置Windows窗体的默认属性

本文关键字:窗体 Windows 默认 属性 设置 何设置 | 更新日期: 2023-09-27 18:16:19

我正在为使用Windows窗体的小型竞赛编写(和设计)速度,我发现自己每次创建新窗体时都会重复更改一些设计属性。这些属性包括:

  • 起动位置
  • 大小
  • FormBorderStyle
  • MaximizeBox

我的问题是:是否有任何方法可以指定我创建的每个表单的默认设置?

c# -如何设置Windows窗体的默认属性

创建一个基本表单,并在构造函数中设置默认属性。添加新表单后,转到代码文件,更改从创建的BaseForm继承的表单。就是这样!!

BaseForm.cs

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace SOF
{
    public class BaseForm : Form
    {
        public BaseForm()
        {
            InitializeComponent();
            this.StartPosition = FormStartPosition.CenterScreen;
            this.Size = new Size(400, 400);
            this.FormBorderStyle = FormBorderStyle.FixedToolWindow;
            this.MaximizeBox = false;
        }
    }
}

FormInherited.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace SOF
{
    public partial class FormInherited : BaseForm
    {
        public FormInherited()
        {
            InitializeComponent();
        }
    }
}