Επεξεργασία

Κοινή χρήση μέσω


DefaultValueAttribute removed from some properties

DefaultValueAttribute has been removed from control properties that are dependent on the default font height.

Version introduced

.NET 8

Previous behavior

The affected properties were decorated with DefaultValueAttribute, and default values were hardcoded according to an assumed application-wide font.

New behavior

Starting in .NET 8, the attribute is removed from certain properties. Design-time default values are calculated at startup based on the current font metrics.

Change category

This change is a behavioral change.

Reason for change

The DefaultValueAttribute attribute is designed to define constant default values used by the Windows Forms designer. In the past, this attribute was used to specify defaults on certain properties that depend on the current font height. A new default font was introduced in .NET Core 3.1, but the attribute values weren't updated accordingly. Moreover, there's now an API to modify application font. Thus, it makes sense to use dynamic default values instead of constant ones.

The designer provides methods to specify dynamic default values, however, for properties decorated with DefaultValueAttribute, it always uses the constant default value instead. The methods for specifying dynamic defaults preserve the design-time functionality provided by the attribute.

DefaultValueAttribute is intended for internal use in design-time scenarios. You shouldn't use it in other scenarios.

Affected APIs

The following table lists the affected properties.

Property Change version
System.Windows.Forms.DataGridViewRow.Height Preview 2
System.Windows.Forms.ListBox.ItemHeight Preview 2