这个让我现在有点难过。我正在创建一个System.Windows.Forms.DataGridView
具有一些合理默认值的派生控件。现在为了明确这一点,它们只是默认值,应该能够在设计器中进行更改。截至目前,我在控件构造函数中设置了默认值:
using System.Drawing;
using System.Windows.Forms;
namespace TruckSmart.Controls
{
/// <summary>
/// An implementation of a System.Windows.Forms.DataGridView with sensible default values.
/// </summary>
public class DataGrid : System.Windows.Forms.DataGridView
{
/// <summary>
/// Initializes a new instance of the TruckSmart.Controls.DataGrid class.
/// </summary>
public DataGrid()
{
AllowUserToAddRows = false;
AllowUserToDeleteRows = false;
AllowUserToOrderColumns = false;
AllowUserToResizeColumns = false;
AllowUserToResizeRows = false;
AutoGenerateColumns = false;
AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells;
AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCells;
BackgroundColor = SystemColors.Window;
BorderStyle = BorderStyle.Fixed3D;
ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.None;
Margin = new Padding(0);
MultiSelect = false;
ReadOnly = true;
RowHeadersVisible = false;
SelectionMode = DataGridViewSelectionMode.FullRowSelect;
AlternatingRowsDefaultCellStyle = new DataGridViewCellStyle()
{
BackColor = Color.FromKnownColor(KnownColor.AliceBlue)
};
ColumnHeadersDefaultCellStyle = new DataGridViewCellStyle()
{
WrapMode = DataGridViewTriState.False
};
}
}
}
使用构造函数的主要问题是,当我在 Visual Studio 中关闭表单设计器并重新打开它时,会再次调用构造函数,并且我之前在设计器中所做的任何更改都会被重置。我应该把这些默认值放在一个特殊的地方吗?