From eae980ea19f156051c5e4ccab0da5c2a260663f1 Mon Sep 17 00:00:00 2001 From: Epica3055 Date: Fri, 4 Aug 2023 08:26:52 +0800 Subject: [PATCH 1/2] Port PropertyGridDesigner NotifyIconDesigner to runtime #4908 --- .../src/System.Design.Forwards.cs | 2 + .../src/Resources/SR.resx | 5 +- .../src/Resources/xlf/SR.cs.xlf | 7 ++- .../src/Resources/xlf/SR.de.xlf | 7 ++- .../src/Resources/xlf/SR.es.xlf | 7 ++- .../src/Resources/xlf/SR.fr.xlf | 7 ++- .../src/Resources/xlf/SR.it.xlf | 7 ++- .../src/Resources/xlf/SR.ja.xlf | 7 ++- .../src/Resources/xlf/SR.ko.xlf | 7 ++- .../src/Resources/xlf/SR.pl.xlf | 7 ++- .../src/Resources/xlf/SR.pt-BR.xlf | 7 ++- .../src/Resources/xlf/SR.ru.xlf | 7 ++- .../src/Resources/xlf/SR.tr.xlf | 7 ++- .../src/Resources/xlf/SR.zh-Hans.xlf | 7 ++- .../src/Resources/xlf/SR.zh-Hant.xlf | 7 ++- .../Forms/Design/NotifyIconDesigner.cs | 55 +++++++++++++++++++ .../Forms/Design/PropertyGridDesigner.cs | 20 +++++++ .../DesignSurface/DemoConsole/MainForm.cs | 2 + .../Forms/Design/DesignerAttributeTests.cs | 2 - 19 files changed, 161 insertions(+), 16 deletions(-) create mode 100644 src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/NotifyIconDesigner.cs create mode 100644 src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/PropertyGridDesigner.cs diff --git a/src/System.Design/src/System.Design.Forwards.cs b/src/System.Design/src/System.Design.Forwards.cs index 365b42c75ba..c25f9f2871b 100644 --- a/src/System.Design/src/System.Design.Forwards.cs +++ b/src/System.Design/src/System.Design.Forwards.cs @@ -44,7 +44,9 @@ [assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.ListViewDesigner))] [assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.MaskedTextBoxDesigner))] [assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.MonthCalendarDesigner))] +[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.NotifyIconDesigner))] [assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.PanelDesigner))] +[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.PropertyGridDesigner))] [assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.PictureBoxDesigner))] [assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.PrintDialogDesigner))] [assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.RadioButtonDesigner))] diff --git a/src/System.Windows.Forms.Design/src/Resources/SR.resx b/src/System.Windows.Forms.Design/src/Resources/SR.resx index 63aba3411de..cbf8e2938fa 100644 --- a/src/System.Windows.Forms.Design/src/Resources/SR.resx +++ b/src/System.Windows.Forms.Design/src/Resources/SR.resx @@ -1446,4 +1446,7 @@ Press Ctrl+Enter to accept Text. Image Size - \ No newline at end of file + + Choose Icon... + + diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.cs.xlf b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.cs.xlf index 545f3baa477..2ef683f0c74 100644 --- a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.cs.xlf +++ b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.cs.xlf @@ -227,6 +227,11 @@ Náhled na vybrané položky + + Choose Icon... + Vybrat ikonu... + + Select the image displayed in the PictureBox Vyberte obrázek zobrazený v ovládacím prvku PictureBox @@ -2219,4 +2224,4 @@ Stisknutím kombinace kláves Ctrl+Enter text přijměte. - \ No newline at end of file + diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.de.xlf b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.de.xlf index 42caea0cae4..bd9e11cf409 100644 --- a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.de.xlf +++ b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.de.xlf @@ -227,6 +227,11 @@ Auswahlvorschau + + Choose Icon... + Symbol auswählen... + + Select the image displayed in the PictureBox In PictureBox angezeigtes Bild auswählen @@ -2219,4 +2224,4 @@ Drücken Sie STRG+EINGABETASTE, um Text zu übernehmen. - \ No newline at end of file + diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.es.xlf b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.es.xlf index af5b400a8ec..0f3573e5b99 100644 --- a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.es.xlf +++ b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.es.xlf @@ -227,6 +227,11 @@ Vista previa seleccionada + + Choose Icon... + Elegir icono... + + Select the image displayed in the PictureBox Seleccione la imagen mostrada en PictureBox @@ -2219,4 +2224,4 @@ Presione Ctrl+Entrar para aceptar el texto. - \ No newline at end of file + diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.fr.xlf b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.fr.xlf index 27974d08fbb..4c7c4f2adb0 100644 --- a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.fr.xlf +++ b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.fr.xlf @@ -227,6 +227,11 @@ Aperçu sélectionné + + Choose Icon... + Choisir une icône... + + Select the image displayed in the PictureBox Sélectionnez l'image affichée dans PictureBox @@ -2219,4 +2224,4 @@ Appuyez sur Ctrl+Entrée pour valider le texte. - \ No newline at end of file + diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.it.xlf b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.it.xlf index 2d9da93673f..8b8bbd8ac91 100644 --- a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.it.xlf +++ b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.it.xlf @@ -227,6 +227,11 @@ Anteprima selezionata + + Choose Icon... + Seleziona icona... + + Select the image displayed in the PictureBox Selezionare l'immagine da visualizzare nel controllo PictureBox. @@ -2219,4 +2224,4 @@ Per accettare testo premere CTRL+INVIO. - \ No newline at end of file + diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.ja.xlf b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.ja.xlf index ffb9f448f8a..03432273343 100644 --- a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.ja.xlf +++ b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.ja.xlf @@ -227,6 +227,11 @@ 選択されたプレビュー + + Choose Icon... + アイコンの選択... + + Select the image displayed in the PictureBox PictureBox に表示されているイメージを選択してください @@ -2219,4 +2224,4 @@ Press Ctrl+Enter to accept Text. - \ No newline at end of file + diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.ko.xlf b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.ko.xlf index 66d2de3c158..771a3f538b2 100644 --- a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.ko.xlf +++ b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.ko.xlf @@ -227,6 +227,11 @@ 선택된 미리 보기 + + Choose Icon... + 아이콘 선택... + + Select the image displayed in the PictureBox PictureBox에 표시된 이미지를 선택합니다. @@ -2219,4 +2224,4 @@ Press Ctrl+Enter to accept Text. - \ No newline at end of file + diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.pl.xlf b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.pl.xlf index 350af370ac0..0edc544b90e 100644 --- a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.pl.xlf +++ b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.pl.xlf @@ -227,6 +227,11 @@ Wybrany podgląd + + Choose Icon... + Wybierz ikonę... + + Select the image displayed in the PictureBox Wybierz obraz wyświetlany w polu PictureBox @@ -2219,4 +2224,4 @@ Naciśnij klawisze Ctrl+Enter, aby zaakceptować tekst. - \ No newline at end of file + diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.pt-BR.xlf b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.pt-BR.xlf index 4f9af4cdc76..561d592891e 100644 --- a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.pt-BR.xlf +++ b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.pt-BR.xlf @@ -227,6 +227,11 @@ Visualização Selecionada + + Choose Icon... + Escolher Ícone... + + Select the image displayed in the PictureBox Selecionar a imagem exibida em PictureBox @@ -2219,4 +2224,4 @@ Pressione Ctrl+Enter para aceitar Texto. - \ No newline at end of file + diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.ru.xlf b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.ru.xlf index e0b042fe497..7cc3d7a732b 100644 --- a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.ru.xlf +++ b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.ru.xlf @@ -227,6 +227,11 @@ Выборочный предварительный просмотр + + Choose Icon... + Выбрать значок… + + Select the image displayed in the PictureBox Выберите изображение, отображаемое в поле PictureBox @@ -2219,4 +2224,4 @@ Press Ctrl+Enter to accept Text. - \ No newline at end of file + diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.tr.xlf b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.tr.xlf index 543ede034a2..461d4f0c8a2 100644 --- a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.tr.xlf +++ b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.tr.xlf @@ -227,6 +227,11 @@ Seçili Önizleme + + Choose Icon... + Simge Seç... + + Select the image displayed in the PictureBox PictureBox içinde gösterilen görüntüyü seçin @@ -2219,4 +2224,4 @@ Metni kabul etmek için Ctrl+Enter tuşlarına basın. - \ No newline at end of file + diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.zh-Hans.xlf b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.zh-Hans.xlf index f0ff024a916..c4da4c647bc 100644 --- a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.zh-Hans.xlf +++ b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.zh-Hans.xlf @@ -227,6 +227,11 @@ 所选预览 + + Choose Icon... + 选择图标... + + Select the image displayed in the PictureBox 选择在 PictureBox 中显示的图像 @@ -2219,4 +2224,4 @@ Press Ctrl+Enter to accept Text. - \ No newline at end of file + diff --git a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.zh-Hant.xlf b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.zh-Hant.xlf index 21bb18f2d25..0fad2be2f07 100644 --- a/src/System.Windows.Forms.Design/src/Resources/xlf/SR.zh-Hant.xlf +++ b/src/System.Windows.Forms.Design/src/Resources/xlf/SR.zh-Hant.xlf @@ -227,6 +227,11 @@ 已選取預覽 + + Choose Icon... + 選擇圖示... + + Select the image displayed in the PictureBox 選取 PictureBox 中顯示的影像 @@ -2219,4 +2224,4 @@ Press Ctrl+Enter to accept Text. - \ No newline at end of file + diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/NotifyIconDesigner.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/NotifyIconDesigner.cs new file mode 100644 index 00000000000..551a710be6c --- /dev/null +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/NotifyIconDesigner.cs @@ -0,0 +1,55 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Collections; +using System.ComponentModel.Design; + +namespace System.Windows.Forms.Design +{ + internal class NotifyIconDesigner : ComponentDesigner + { + private DesignerActionListCollection? _actionLists; + + public override void InitializeNewComponent(IDictionary defaultValues) + { + base.InitializeNewComponent(defaultValues); + NotifyIcon icon = (NotifyIcon)Component; + icon.Visible = true; + } + + public override DesignerActionListCollection ActionLists + { + get + { + if (_actionLists is null) + { + _actionLists = new DesignerActionListCollection(); + _actionLists.Add(new NotifyIconActionList(this)); + } + + return _actionLists; + } + } + } + + internal class NotifyIconActionList : DesignerActionList + { + private NotifyIconDesigner _designer; + public NotifyIconActionList(NotifyIconDesigner designer) : base(designer.Component) + { + _designer = designer; + } + + public void ChooseIcon() + { + EditorServiceContext.EditValue(_designer, Component, "Icon"); + } + + public override DesignerActionItemCollection GetSortedActionItems() + { + DesignerActionItemCollection items = new DesignerActionItemCollection(); + items.Add(new DesignerActionMethodItem(this, "ChooseIcon", SR.ChooseIconDisplayName, true)); + return items; + } + } +} diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/PropertyGridDesigner.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/PropertyGridDesigner.cs new file mode 100644 index 00000000000..a6851f2b926 --- /dev/null +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/PropertyGridDesigner.cs @@ -0,0 +1,20 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Collections; + +namespace System.Windows.Forms.Design; + +internal class PropertyGridDesigner : ControlDesigner +{ + protected override void PreFilterProperties(IDictionary properties) + { + // Remove the ScrollableControl properties... + properties.Remove(nameof(PropertyGrid.AutoScroll)); + properties.Remove(nameof(PropertyGrid.AutoScrollMargin)); + properties.Remove(nameof(PropertyGrid.AutoScrollMinSize)); + properties.Remove(nameof(PropertyGrid.DockPadding)); + + base.PreFilterProperties(properties); + } +} diff --git a/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DemoConsole/MainForm.cs b/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DemoConsole/MainForm.cs index eb31dc70e49..340fa1aecf2 100644 --- a/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DemoConsole/MainForm.cs +++ b/src/System.Windows.Forms/tests/IntegrationTests/DesignSurface/DemoConsole/MainForm.cs @@ -236,6 +236,8 @@ private void CreateDesignSurface(int n) surface.CreateControl(new Size(400, 100), new Point(12, 21)); surface.CreateControl(new Size(290, 160), new Point(20, 150)); + surface.CreateControl(new Size(200, 150), new Point(430, 23)); + surface.CreateComponent(); } break; diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/Design/DesignerAttributeTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/Design/DesignerAttributeTests.cs index b96cf01fd05..4422f97806e 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/Design/DesignerAttributeTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/Design/DesignerAttributeTests.cs @@ -31,8 +31,6 @@ public class DesignerAttributeTests "System.Windows.Forms.Design.DataGridViewDesigner, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Windows.Forms.Design.FlowLayoutPanelDesigner, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Windows.Forms.Design.FolderBrowserDialogDesigner, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", - "System.Windows.Forms.Design.NotifyIconDesigner, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", - "System.Windows.Forms.Design.PropertyGridDesigner, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Windows.Forms.Design.SaveFileDialogDesigner, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Windows.Forms.Design.StatusBarDesigner, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Windows.Forms.Design.ToolStripContainerDesigner, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", From 251491bb0053f75c22c4bd1da521eba36cdf88f8 Mon Sep 17 00:00:00 2001 From: Epica3055 Date: Thu, 10 Aug 2023 10:47:17 +0800 Subject: [PATCH 2/2] simplify code --- .../Forms/Design/NotifyIconDesigner.cs | 28 ++--------------- .../Design/NotifyIconDesignerActionList.cs | 30 +++++++++++++++++++ 2 files changed, 33 insertions(+), 25 deletions(-) create mode 100644 src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/NotifyIconDesignerActionList.cs diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/NotifyIconDesigner.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/NotifyIconDesigner.cs index 551a710be6c..de1ae643277 100644 --- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/NotifyIconDesigner.cs +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/NotifyIconDesigner.cs @@ -21,35 +21,13 @@ public override DesignerActionListCollection ActionLists { get { - if (_actionLists is null) + _actionLists ??= new DesignerActionListCollection { - _actionLists = new DesignerActionListCollection(); - _actionLists.Add(new NotifyIconActionList(this)); - } + new NotifyIconActionList(this) + }; return _actionLists; } } } - - internal class NotifyIconActionList : DesignerActionList - { - private NotifyIconDesigner _designer; - public NotifyIconActionList(NotifyIconDesigner designer) : base(designer.Component) - { - _designer = designer; - } - - public void ChooseIcon() - { - EditorServiceContext.EditValue(_designer, Component, "Icon"); - } - - public override DesignerActionItemCollection GetSortedActionItems() - { - DesignerActionItemCollection items = new DesignerActionItemCollection(); - items.Add(new DesignerActionMethodItem(this, "ChooseIcon", SR.ChooseIconDisplayName, true)); - return items; - } - } } diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/NotifyIconDesignerActionList.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/NotifyIconDesignerActionList.cs new file mode 100644 index 00000000000..2d48e3c3c2b --- /dev/null +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/NotifyIconDesignerActionList.cs @@ -0,0 +1,30 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.ComponentModel.Design; + +namespace System.Windows.Forms.Design +{ + internal class NotifyIconActionList : DesignerActionList + { + private readonly NotifyIconDesigner _designer; + public NotifyIconActionList(NotifyIconDesigner designer) : base(designer.Component) + { + _designer = designer; + } + + public void ChooseIcon() + { + EditorServiceContext.EditValue(_designer, Component, "Icon"); + } + + public override DesignerActionItemCollection GetSortedActionItems() + { + var items = new DesignerActionItemCollection + { + new DesignerActionMethodItem(this, "ChooseIcon", SR.ChooseIconDisplayName, true) + }; + return items; + } + } +}