diff --git a/src/System.Windows.Forms.Design/src/PublicAPI.Shipped.txt b/src/System.Windows.Forms.Design/src/PublicAPI.Shipped.txt index 2c8a351b308..e838e6b2dff 100644 --- a/src/System.Windows.Forms.Design/src/PublicAPI.Shipped.txt +++ b/src/System.Windows.Forms.Design/src/PublicAPI.Shipped.txt @@ -16,9 +16,9 @@ ~override System.Windows.Forms.Design.ComponentTray.OnMouseMove(System.Windows.Forms.MouseEventArgs e) -> void ~override System.Windows.Forms.Design.ComponentTray.OnMouseUp(System.Windows.Forms.MouseEventArgs e) -> void ~override System.Windows.Forms.Design.ComponentTray.OnPaint(System.Windows.Forms.PaintEventArgs pe) -> void -~override System.Windows.Forms.Design.ControlDesigner.Initialize(System.ComponentModel.IComponent component) -> void -~override System.Windows.Forms.Design.ControlDesigner.InitializeExistingComponent(System.Collections.IDictionary defaultValues) -> void -~override System.Windows.Forms.Design.ControlDesigner.InitializeNewComponent(System.Collections.IDictionary defaultValues) -> void +override System.Windows.Forms.Design.ControlDesigner.Initialize(System.ComponentModel.IComponent! component) -> void +override System.Windows.Forms.Design.ControlDesigner.InitializeExistingComponent(System.Collections.IDictionary? defaultValues) -> void +override System.Windows.Forms.Design.ControlDesigner.InitializeNewComponent(System.Collections.IDictionary? defaultValues) -> void ~override System.Windows.Forms.Design.ControlDesigner.PreFilterProperties(System.Collections.IDictionary properties) -> void ~override System.Windows.Forms.Design.DocumentDesigner.GetGlyphs(System.Windows.Forms.Design.Behavior.GlyphSelectionType selectionType) -> System.Windows.Forms.Design.Behavior.GlyphCollection ~override System.Windows.Forms.Design.DocumentDesigner.Initialize(System.ComponentModel.IComponent component) -> void @@ -88,7 +88,7 @@ ~System.Windows.Forms.Design.ComponentTray.IsTrayComponent(System.ComponentModel.IComponent comp) -> bool ~System.Windows.Forms.Design.ComponentTray.SetLocation(System.ComponentModel.IComponent receiver, System.Drawing.Point location) -> void ~System.Windows.Forms.Design.ComponentTray.SetTrayLocation(System.ComponentModel.IComponent receiver, System.Drawing.Point location) -> void -~System.Windows.Forms.Design.ControlDesigner.HookChildControls(System.Windows.Forms.Control firstChild) -> void +System.Windows.Forms.Design.ControlDesigner.HookChildControls(System.Windows.Forms.Control! firstChild) -> void ~System.Windows.Forms.Design.ControlDesigner.UnhookChildControls(System.Windows.Forms.Control firstChild) -> void ~System.Windows.Forms.Design.ParentControlDesigner.AddPaddingSnapLines(ref System.Collections.ArrayList snapLines) -> void ~System.Windows.Forms.Design.ParentControlDesigner.CreateTool(System.Drawing.Design.ToolboxItem tool) -> void @@ -102,13 +102,13 @@ ~virtual System.Windows.Forms.Design.ComponentTray.CanCreateComponentFromTool(System.Drawing.Design.ToolboxItem tool) -> bool ~virtual System.Windows.Forms.Design.ComponentTray.CanDisplayComponent(System.ComponentModel.IComponent component) -> bool ~virtual System.Windows.Forms.Design.ComponentTray.RemoveComponent(System.ComponentModel.IComponent component) -> void -~virtual System.Windows.Forms.Design.ControlDesigner.GetGlyphs(System.Windows.Forms.Design.Behavior.GlyphSelectionType selectionType) -> System.Windows.Forms.Design.Behavior.GlyphCollection -~virtual System.Windows.Forms.Design.ControlDesigner.OnDragComplete(System.Windows.Forms.DragEventArgs de) -> void -~virtual System.Windows.Forms.Design.ControlDesigner.OnDragDrop(System.Windows.Forms.DragEventArgs de) -> void -~virtual System.Windows.Forms.Design.ControlDesigner.OnDragEnter(System.Windows.Forms.DragEventArgs de) -> void -~virtual System.Windows.Forms.Design.ControlDesigner.OnDragLeave(System.EventArgs e) -> void -~virtual System.Windows.Forms.Design.ControlDesigner.OnDragOver(System.Windows.Forms.DragEventArgs de) -> void -~virtual System.Windows.Forms.Design.ControlDesigner.OnGiveFeedback(System.Windows.Forms.GiveFeedbackEventArgs e) -> void +virtual System.Windows.Forms.Design.ControlDesigner.GetGlyphs(System.Windows.Forms.Design.Behavior.GlyphSelectionType selectionType) -> System.Windows.Forms.Design.Behavior.GlyphCollection! +virtual System.Windows.Forms.Design.ControlDesigner.OnDragComplete(System.Windows.Forms.DragEventArgs! de) -> void +virtual System.Windows.Forms.Design.ControlDesigner.OnDragDrop(System.Windows.Forms.DragEventArgs! de) -> void +virtual System.Windows.Forms.Design.ControlDesigner.OnDragEnter(System.Windows.Forms.DragEventArgs! de) -> void +virtual System.Windows.Forms.Design.ControlDesigner.OnDragLeave(System.EventArgs! e) -> void +virtual System.Windows.Forms.Design.ControlDesigner.OnDragOver(System.Windows.Forms.DragEventArgs! de) -> void +virtual System.Windows.Forms.Design.ControlDesigner.OnGiveFeedback(System.Windows.Forms.GiveFeedbackEventArgs! e) -> void ~virtual System.Windows.Forms.Design.ControlDesigner.OnPaintAdornments(System.Windows.Forms.PaintEventArgs pe) -> void ~virtual System.Windows.Forms.Design.DocumentDesigner.GetToolSupported(System.Drawing.Design.ToolboxItem tool) -> bool ~virtual System.Windows.Forms.Design.DocumentDesigner.ToolPicked(System.Drawing.Design.ToolboxItem tool) -> void diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ButtonBaseDesigner.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ButtonBaseDesigner.cs index dc6347419b1..01b4856ef42 100644 --- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ButtonBaseDesigner.cs +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ButtonBaseDesigner.cs @@ -22,7 +22,7 @@ public ButtonBaseDesigner() AutoResizeHandles = true; } - public override void InitializeNewComponent(IDictionary defaultValues) + public override void InitializeNewComponent(IDictionary? defaultValues) { base.InitializeNewComponent(defaultValues); diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ComboBoxDesigner.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ComboBoxDesigner.cs index 0aa91e30c29..a5051acbf65 100644 --- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ComboBoxDesigner.cs +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ComboBoxDesigner.cs @@ -74,7 +74,7 @@ public override void Initialize(IComponent component) /// /// We override this so we can clear the text field set by controldesigner. /// - public override void InitializeNewComponent(IDictionary defaultValues) + public override void InitializeNewComponent(IDictionary? defaultValues) { base.InitializeNewComponent(defaultValues); diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ControlDesigner.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ControlDesigner.cs index d09d6f7f9bf..6307b1060b3 100644 --- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ControlDesigner.cs +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ControlDesigner.cs @@ -462,9 +462,9 @@ protected override void Dispose(bool disposing) if (_removalNotificationHooked) { - if (TryGetService(out IComponentChangeService? csc)) + if (TryGetService(out IComponentChangeService? componentChangeService)) { - csc.ComponentRemoved -= new ComponentEventHandler(DataSource_ComponentRemoved); + componentChangeService.ComponentRemoved -= new ComponentEventHandler(DataSource_ComponentRemoved); } _removalNotificationHooked = false; @@ -551,9 +551,9 @@ private void DataSource_ComponentRemoved(object? sender, ComponentEventArgs e) // if after removing those bindings the collection is empty, then unhook the changeNotificationService if (ctl.DataBindings.Count == 0) { - if (TryGetService(out IComponentChangeService? csc)) + if (TryGetService(out IComponentChangeService? componentChangeService)) { - csc.ComponentRemoved -= new ComponentEventHandler(DataSource_ComponentRemoved); + componentChangeService.ComponentRemoved -= new ComponentEventHandler(DataSource_ComponentRemoved); } _removalNotificationHooked = false; @@ -718,7 +718,7 @@ protected virtual ControlBodyGlyph GetControlGlyph(GlyphSelectionType selectionT } internal ControlBodyGlyph GetControlGlyphInternal(GlyphSelectionType selectionType) => GetControlGlyph(selectionType); -#nullable disable + /// /// Returns a collection of Glyph objects representing the selection borders and grab handles for a standard /// control. Note that based on 'selectionType' the Glyphs returned will either: represent a fully resizeable @@ -733,6 +733,11 @@ public virtual GlyphCollection GetGlyphs(GlyphSelectionType selectionType) return glyphs; } + if (BehaviorService is null) + { + throw new InvalidOperationException(); + } + Rectangle translatedBounds = BehaviorService.ControlRectInAdornerWindow(Control); bool primarySelection = (selectionType == GlyphSelectionType.SelectedPrimary); SelectionRules rules = SelectionRules; @@ -761,9 +766,9 @@ public virtual GlyphCollection GetGlyphs(GlyphSelectionType selectionType) // enable the designeractionpanel for this control if it needs one if (TypeDescriptor.GetAttributes(Component).Contains(DesignTimeVisibleAttribute.Yes) - && _behaviorService.DesignerActionUI is not null) + && _behaviorService?.DesignerActionUI is { } designerActionUI) { - Glyph dapGlyph = _behaviorService.DesignerActionUI.GetDesignerActionGlyph(Component); + Glyph? dapGlyph = designerActionUI.GetDesignerActionGlyph(Component); if (dapGlyph is not null) { glyphs.Insert(0, dapGlyph); // we WANT to be in front of the other UI @@ -819,9 +824,9 @@ public virtual GlyphCollection GetGlyphs(GlyphSelectionType selectionType) // enable the designeractionpanel for this control if it needs one if (TypeDescriptor.GetAttributes(Component).Contains(DesignTimeVisibleAttribute.Yes) - && _behaviorService.DesignerActionUI is not null) + && _behaviorService?.DesignerActionUI is { } designerActionUI) { - Glyph dapGlyph = _behaviorService.DesignerActionUI.GetDesignerActionGlyph(Component); + Glyph? dapGlyph = designerActionUI.GetDesignerActionGlyph(Component); if (dapGlyph is not null) { glyphs.Insert(0, dapGlyph); // we WANT to be in front of the other UI @@ -886,9 +891,9 @@ protected void HookChildControls(Control firstChild) } } - private void OnChildHandleCreated(object sender, EventArgs e) + private void OnChildHandleCreated(object? sender, EventArgs e) { - Control child = sender as Control; + Control? child = sender as Control; Debug.Assert(child is not null); @@ -908,17 +913,17 @@ public override void Initialize(IComponent component) // Otherwise, grab the shadow value from the control directly and then set the control to be visible if it // is not the root component. Root components will be set to visible = true in their own time by the view. PropertyDescriptorCollection props = TypeDescriptor.GetProperties(component.GetType()); - PropertyDescriptor visibleProp = props["Visible"]; + PropertyDescriptor? visibleProp = props["Visible"]; Visible = visibleProp is null || visibleProp.PropertyType != typeof(bool) || !visibleProp.ShouldSerializeValue(component) - || (bool)visibleProp.GetValue(component); + || (bool)visibleProp.GetValue(component)!; - PropertyDescriptor enabledProp = props["Enabled"]; + PropertyDescriptor? enabledProp = props["Enabled"]; Enabled = enabledProp is null || enabledProp.PropertyType != typeof(bool) || !enabledProp.ShouldSerializeValue(component) - || (bool)enabledProp.GetValue(component); + || (bool)enabledProp.GetValue(component)!; base.Initialize(component); @@ -927,16 +932,16 @@ public override void Initialize(IComponent component) // This is to create the action in the DAP for this component if it requires docking/undocking logic AttributeCollection attributes = TypeDescriptor.GetAttributes(Component); - DockingAttribute dockingAttribute = (DockingAttribute)attributes[typeof(DockingAttribute)]; + DockingAttribute? dockingAttribute = (DockingAttribute?)attributes[typeof(DockingAttribute)]; if (dockingAttribute is not null && dockingAttribute.DockingBehavior != DockingBehavior.Never) { // Create the action for this control _dockingAction = new DockingActionList(this); // Add our 'dock in parent' or 'undock in parent' action - if (TryGetService(out DesignerActionService das)) + if (TryGetService(out DesignerActionService? designerActionService)) { - das.Add(Component, _dockingAction); + designerActionService.Add(Component, _dockingAction); } } @@ -963,7 +968,9 @@ public override void Initialize(IComponent component) } // If we are an inherited control, notify our inheritance UI - if (Inherited && _host is not null && _host.RootComponent != component) + if (Inherited && _host is not null + && _host.RootComponent != component + && InheritanceAttribute is not null) { _inheritanceUI = GetService(); _inheritanceUI?.AddInheritedControl(Control, InheritanceAttribute.InheritanceLevel); @@ -989,25 +996,25 @@ public override void Initialize(IComponent component) // This is a workaround to some problems with the ComponentCache that we should fix. When this is removed // remember to change ComponentCache's RemoveEntry method back to private (from internal). - private void OnSizeChanged(object sender, EventArgs e) + private void OnSizeChanged(object? sender, EventArgs e) { object component = Component; - if (TryGetService(out ComponentCache cache) && component is not null) + if (TryGetService(out ComponentCache? cache) && component is not null) { cache.RemoveEntry(component); } } - private void OnLocationChanged(object sender, EventArgs e) + private void OnLocationChanged(object? sender, EventArgs e) { object component = Component; - if (TryGetService(out ComponentCache cache) && component is not null) + if (TryGetService(out ComponentCache? cache) && component is not null) { cache.RemoveEntry(component); } } - private void OnParentChanged(object sender, EventArgs e) + private void OnParentChanged(object? sender, EventArgs e) { if (Control.IsHandleCreated) { @@ -1015,7 +1022,7 @@ private void OnParentChanged(object sender, EventArgs e) } } - private void OnControlRemoved(object sender, ControlEventArgs e) + private void OnControlRemoved(object? sender, ControlEventArgs e) { if (e.Control is not null) { @@ -1029,7 +1036,7 @@ private void OnControlRemoved(object sender, ControlEventArgs e) } } - private void DataBindingsCollectionChanged(object sender, CollectionChangeEventArgs e) + private void DataBindingsCollectionChanged(object? sender, CollectionChangeEventArgs e) { // It is possible to use the control designer with NON CONTROl types. if (Component is Control ctl) @@ -1037,9 +1044,9 @@ private void DataBindingsCollectionChanged(object sender, CollectionChangeEventA if (ctl.DataBindings.Count == 0 && _removalNotificationHooked) { // Remove the notification for the ComponentRemoved event - if (TryGetService(out IComponentChangeService csc)) + if (TryGetService(out IComponentChangeService? componentChangeService)) { - csc.ComponentRemoved -= new ComponentEventHandler(DataSource_ComponentRemoved); + componentChangeService.ComponentRemoved -= new ComponentEventHandler(DataSource_ComponentRemoved); } _removalNotificationHooked = false; @@ -1047,9 +1054,9 @@ private void DataBindingsCollectionChanged(object sender, CollectionChangeEventA else if (ctl.DataBindings.Count > 0 && !_removalNotificationHooked) { // Add the notification for the ComponentRemoved event - if (TryGetService(out IComponentChangeService csc)) + if (TryGetService(out IComponentChangeService? componentChangeService)) { - csc.ComponentRemoved += new ComponentEventHandler(DataSource_ComponentRemoved); + componentChangeService.ComponentRemoved += new ComponentEventHandler(DataSource_ComponentRemoved); } _removalNotificationHooked = true; @@ -1057,7 +1064,7 @@ private void DataBindingsCollectionChanged(object sender, CollectionChangeEventA } } - private void OnEnabledChanged(object sender, EventArgs e) + private void OnEnabledChanged(object? sender, EventArgs e) { if (!_enabledchangerecursionguard) { @@ -1079,7 +1086,7 @@ private void OnEnabledChanged(object sender, EventArgs e) /// private bool AllowDrop { - get => (bool)ShadowProperties[nameof(AllowDrop)]; + get => (bool)ShadowProperties[nameof(AllowDrop)]!; set => ShadowProperties[nameof(AllowDrop)] = value; } @@ -1088,32 +1095,32 @@ private bool AllowDrop /// private bool Enabled { - get => (bool)ShadowProperties[nameof(Enabled)]; + get => (bool)ShadowProperties[nameof(Enabled)]!; set => ShadowProperties[nameof(Enabled)] = value; } private bool Visible { - get => (bool)ShadowProperties[nameof(Visible)]; + get => (bool)ShadowProperties[nameof(Visible)]!; set => ShadowProperties[nameof(Visible)] = value; } /// /// ControlDesigner overrides this method to handle after-drop cases. /// - public override void InitializeExistingComponent(IDictionary defaultValues) + public override void InitializeExistingComponent(IDictionary? defaultValues) { base.InitializeExistingComponent(defaultValues); // unhook any sited children that got ChildWindowTargets - foreach (Control c in Control.Controls) + foreach (Control control in Control.Controls) { - if (c is not null) + if (control is not null) { - ISite site = c.Site; - if (site is not null && c.WindowTarget is ChildWindowTarget target) + ISite? site = control.Site; + if (site is not null && control.WindowTarget is ChildWindowTarget target) { - c.WindowTarget = target.OldWindowTarget; + control.WindowTarget = target.OldWindowTarget; } } } @@ -1126,12 +1133,12 @@ public override void InitializeExistingComponent(IDictionary defaultValues) /// connects the control to its parent and positions it. If you override this method, you should always /// call base. /// - public override void InitializeNewComponent(IDictionary defaultValues) + public override void InitializeNewComponent(IDictionary? defaultValues) { - ISite site = Component.Site; + ISite? site = Component.Site; if (site is not null) { - PropertyDescriptor textProp = TypeDescriptor.GetProperties(Component)["Text"]; + PropertyDescriptor? textProp = TypeDescriptor.GetProperties(Component)["Text"]; if (textProp is not null && textProp.PropertyType == typeof(string) && !textProp.IsReadOnly && textProp.IsBrowsable) { textProp.SetValue(Component, site.Name); @@ -1139,7 +1146,7 @@ public override void InitializeNewComponent(IDictionary defaultValues) } if (defaultValues is not null && defaultValues["Parent"] is IComponent parent - && TryGetService(out IDesignerHost host)) + && TryGetService(out IDesignerHost? host)) { if (host.GetDesigner(parent) is ParentControlDesigner parentDesigner) { @@ -1150,7 +1157,7 @@ public override void InitializeNewComponent(IDictionary defaultValues) { // Some containers are docked differently (instead of DockStyle.None) when they are added through the designer AttributeCollection attributes = TypeDescriptor.GetAttributes(Component); - DockingAttribute dockingAttribute = (DockingAttribute)attributes[typeof(DockingAttribute)]; + DockingAttribute? dockingAttribute = (DockingAttribute?)attributes[typeof(DockingAttribute)]; if (dockingAttribute is not null && dockingAttribute.DockingBehavior != DockingBehavior.Never && dockingAttribute.DockingBehavior == DockingBehavior.AutoDock) @@ -1167,7 +1174,7 @@ public override void InitializeNewComponent(IDictionary defaultValues) if (onlyNonDockedChild) { - PropertyDescriptor dockProp = TypeDescriptor.GetProperties(Component)["Dock"]; + PropertyDescriptor? dockProp = TypeDescriptor.GetProperties(Component)["Dock"]; if (dockProp is not null && dockProp.IsBrowsable) { dockProp.SetValue(Component, DockStyle.Fill); @@ -1188,10 +1195,10 @@ public override void InitializeNewComponent(IDictionary defaultValues) [Obsolete("This method has been deprecated. Use InitializeNewComponent instead. https://go.microsoft.com/fwlink/?linkid=14202")] public override void OnSetComponentDefaults() { - ISite site = Component.Site; + ISite? site = Component.Site; if (site is not null) { - PropertyDescriptor textProp = TypeDescriptor.GetProperties(Component)["Text"]; + PropertyDescriptor? textProp = TypeDescriptor.GetProperties(Component)["Text"]; if (textProp is not null && textProp.IsBrowsable) { textProp.SetValue(Component, site.Name); @@ -1284,7 +1291,7 @@ protected virtual void OnDragOver(DragEventArgs de) protected virtual void OnGiveFeedback(GiveFeedbackEventArgs e) { } - +#nullable disable /// /// Called in response to the left mouse button being pressed on a component. It ensures that the component is selected. /// diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/RadioButtonDesigner.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/RadioButtonDesigner.cs index 96f6fa4e03e..0ea3e7938ab 100644 --- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/RadioButtonDesigner.cs +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/RadioButtonDesigner.cs @@ -13,7 +13,7 @@ namespace System.Windows.Forms.Design; /// internal class RadioButtonDesigner : ButtonBaseDesigner { - public override void InitializeNewComponent(IDictionary defaultValues) + public override void InitializeNewComponent(IDictionary? defaultValues) { base.InitializeNewComponent(defaultValues); diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/RichTextBoxDesigner.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/RichTextBoxDesigner.cs index 6b8bc432543..1f22cdc3fd1 100644 --- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/RichTextBoxDesigner.cs +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/RichTextBoxDesigner.cs @@ -20,7 +20,7 @@ internal class RichTextBoxDesigner : TextBoxBaseDesigner /// meaningful default values in the control. The default implementation of this /// sets the control's text to its name. /// - public override void InitializeNewComponent(IDictionary defaultValues) + public override void InitializeNewComponent(IDictionary? defaultValues) { base.InitializeNewComponent(defaultValues); diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/TextBoxBaseDesigner.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/TextBoxBaseDesigner.cs index 470844509e7..7e34942dab1 100644 --- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/TextBoxBaseDesigner.cs +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/TextBoxBaseDesigner.cs @@ -86,7 +86,7 @@ private void ResetText() /// We override this so we can clear the text field set by controldesigner. /// /// The default values. - public override void InitializeNewComponent(IDictionary defaultValues) + public override void InitializeNewComponent(IDictionary? defaultValues) { base.InitializeNewComponent(defaultValues);