diff --git a/src/System.Windows.Forms/src/Resources/SR.resx b/src/System.Windows.Forms/src/Resources/SR.resx
index 8de7a251221..8e999923c63 100644
--- a/src/System.Windows.Forms/src/Resources/SR.resx
+++ b/src/System.Windows.Forms/src/Resources/SR.resx
@@ -5753,10 +5753,10 @@ Stack trace where the illegal operation occurred was:
Occurs when a tab page is being selected.
-
+
TabPage cannot be added to a '{0}'. TabPages can only be added to TabControls.
-
+
TabPage cannot be added to another TabPage. TabPages can only be added to TabControls.
diff --git a/src/System.Windows.Forms/src/Resources/xlf/SR.cs.xlf b/src/System.Windows.Forms/src/Resources/xlf/SR.cs.xlf
index 4376647a1a4..25ce1f9aa3d 100644
--- a/src/System.Windows.Forms/src/Resources/xlf/SR.cs.xlf
+++ b/src/System.Windows.Forms/src/Resources/xlf/SR.cs.xlf
@@ -9511,12 +9511,12 @@ Trasování zásobníku, kde došlo k neplatné operaci:
Funkce není v tomto operačním systému podporována.
-
+ Objekt TabPage nelze přidat k objektu {0}. Objekt TabPages lze přidat pouze k ovládacímu prvku TabControls.
-
+ Objekt TabPage nelze přidat k jinému ovládacímu prvku TabPage. Objekt TabPages lze přidat pouze k ovládacímu prvku TabControls.
diff --git a/src/System.Windows.Forms/src/Resources/xlf/SR.de.xlf b/src/System.Windows.Forms/src/Resources/xlf/SR.de.xlf
index bf0fa495ecf..0bcc5289381 100644
--- a/src/System.Windows.Forms/src/Resources/xlf/SR.de.xlf
+++ b/src/System.Windows.Forms/src/Resources/xlf/SR.de.xlf
@@ -9511,12 +9511,12 @@ Stapelüberwachung, in der der unzulässige Vorgang auftrat:
Das Feature wird bei diesem Betriebssystem nicht unterstützt.
-
+ TabPage kann nicht zu einem {0} hinzugefügt werden. TabPages können nur zu TabControls hinzugefügt werden.
-
+ TabPage kann nicht zu einer anderen TabPage hinzugefügt werden. TabPages können nur zu TabControls hinzugefügt werden.
diff --git a/src/System.Windows.Forms/src/Resources/xlf/SR.es.xlf b/src/System.Windows.Forms/src/Resources/xlf/SR.es.xlf
index 59b79adc3d9..e12178da10a 100644
--- a/src/System.Windows.Forms/src/Resources/xlf/SR.es.xlf
+++ b/src/System.Windows.Forms/src/Resources/xlf/SR.es.xlf
@@ -9511,12 +9511,12 @@ El seguimiento de la pila donde tuvo lugar la operación no válida fue:
Este sistema operativo no admite esta característica.
-
+ No se puede agregar TabPage a '{0}'. Sólo se pueden agregar TabPages a TabControls.
-
+ No se puede agregar una TabPage a otra TabPage. Sólo se pueden agregar TabPages a TabControls.
diff --git a/src/System.Windows.Forms/src/Resources/xlf/SR.fr.xlf b/src/System.Windows.Forms/src/Resources/xlf/SR.fr.xlf
index 166cefef57d..d11cd0eef3f 100644
--- a/src/System.Windows.Forms/src/Resources/xlf/SR.fr.xlf
+++ b/src/System.Windows.Forms/src/Resources/xlf/SR.fr.xlf
@@ -9511,12 +9511,12 @@ Cette opération non conforme s'est produite sur la trace de la pile :
Fonctionnalité non prise en charge par ce système d'exploitation.
-
+ Un TabPage ne peut pas être ajouté à un '{0}'. Les TabPages ne peuvent être ajoutés qu'aux TabControls.
-
+ Un TabPage ne peut pas être ajouté à un autre TabPage. Les TabPages ne peuvent être ajoutés qu'aux TabControls.
diff --git a/src/System.Windows.Forms/src/Resources/xlf/SR.it.xlf b/src/System.Windows.Forms/src/Resources/xlf/SR.it.xlf
index fdec11eb0a7..594155f5b85 100644
--- a/src/System.Windows.Forms/src/Resources/xlf/SR.it.xlf
+++ b/src/System.Windows.Forms/src/Resources/xlf/SR.it.xlf
@@ -9511,12 +9511,12 @@ Traccia dello stack da cui si è verificata l'operazione non valida:
Funzionalità non supportata in questo sistema operativo.
-
+ Impossibile aggiungere un oggetto TabPage a '{0}'. Gli oggetti TabPage possono essere aggiunti solo a una classe TabControl.
-
+ Impossibile aggiungere un oggetto TabPage a un altro oggetto TabPage. Gli oggetti TabPage possono essere aggiunti solo a una classe TabControl.
diff --git a/src/System.Windows.Forms/src/Resources/xlf/SR.ja.xlf b/src/System.Windows.Forms/src/Resources/xlf/SR.ja.xlf
index 49b7e7c84ae..0425b468e01 100644
--- a/src/System.Windows.Forms/src/Resources/xlf/SR.ja.xlf
+++ b/src/System.Windows.Forms/src/Resources/xlf/SR.ja.xlf
@@ -9511,12 +9511,12 @@ Stack trace where the illegal operation occurred was:
機能はこのオペレーティング システムでサポートされていません。
-
+ TabPage を '{0}' に追加できません。 TabPages は TabControls にのみ追加できます。
-
+ TabPage を他の TabPage に追加できません。 TabPages は、TabControls にのみ追加できます。
diff --git a/src/System.Windows.Forms/src/Resources/xlf/SR.ko.xlf b/src/System.Windows.Forms/src/Resources/xlf/SR.ko.xlf
index c16c90d0b7d..5500bfcbed7 100644
--- a/src/System.Windows.Forms/src/Resources/xlf/SR.ko.xlf
+++ b/src/System.Windows.Forms/src/Resources/xlf/SR.ko.xlf
@@ -9511,12 +9511,12 @@ Stack trace where the illegal operation occurred was:
이 운영 시스템에서 지원되지 않는 기능입니다.
-
+ TabPage를 '{0}'에 추가할 수 없습니다. TabPages는 TabControls에만 추가할 수 있습니다.
-
+ TabPage를 다른 TabPage에 추가할 수 없습니다. TabPages는 TabControls에만 추가할 수 있습니다.
diff --git a/src/System.Windows.Forms/src/Resources/xlf/SR.pl.xlf b/src/System.Windows.Forms/src/Resources/xlf/SR.pl.xlf
index 63d1708b860..06d1eacd828 100644
--- a/src/System.Windows.Forms/src/Resources/xlf/SR.pl.xlf
+++ b/src/System.Windows.Forms/src/Resources/xlf/SR.pl.xlf
@@ -9511,12 +9511,12 @@ Stos śledzenia, w którym wystąpiła zabroniona operacja:
Funkcja nie jest obsługiwana w tym systemie operacyjnym.
-
+ Nie można dodać elementu TabPage do elementu „{0}”. Elementy TabPage mogą być dodawane tylko do elementów TabControl.
-
+ Nie można dodać elementu TabPage do innego elementu TabPage. Elementy TabPage mogą być dodawane tylko do elementów TabControl.
diff --git a/src/System.Windows.Forms/src/Resources/xlf/SR.pt-BR.xlf b/src/System.Windows.Forms/src/Resources/xlf/SR.pt-BR.xlf
index 64358552617..cbe8cae65be 100644
--- a/src/System.Windows.Forms/src/Resources/xlf/SR.pt-BR.xlf
+++ b/src/System.Windows.Forms/src/Resources/xlf/SR.pt-BR.xlf
@@ -9511,12 +9511,12 @@ Rastreamento de pilha em que a operação ilegal ocorreu:
Não há suporte para o recurso com este sistema operacional.
-
+ TabPage não pode ser adicionado a '{0}'. TabPages só podem ser adicionados a TabControls.
-
+ TabPage não pode ser adicionado a outro TabPage. TabPages só podem ser adicionados a TabControls.
diff --git a/src/System.Windows.Forms/src/Resources/xlf/SR.ru.xlf b/src/System.Windows.Forms/src/Resources/xlf/SR.ru.xlf
index f80154e7d0b..b2562d241c4 100644
--- a/src/System.Windows.Forms/src/Resources/xlf/SR.ru.xlf
+++ b/src/System.Windows.Forms/src/Resources/xlf/SR.ru.xlf
@@ -9512,12 +9512,12 @@ Stack trace where the illegal operation occurred was:
Функция не поддерживается в данной ОС.
-
+ TabPage нельзя добавить к '{0}'. TabPages можно добавлять только к TabControls.
-
+ TabPage нельзя добавить к другой TabPage. TabPages можно добавлять только к TabControls.
diff --git a/src/System.Windows.Forms/src/Resources/xlf/SR.tr.xlf b/src/System.Windows.Forms/src/Resources/xlf/SR.tr.xlf
index 0e07de2d6c8..65caa7ebcff 100644
--- a/src/System.Windows.Forms/src/Resources/xlf/SR.tr.xlf
+++ b/src/System.Windows.Forms/src/Resources/xlf/SR.tr.xlf
@@ -9511,12 +9511,12 @@ Geçersiz işlemin gerçekleştiği yığın izi:
Özellik bu işletim sistemiyle desteklenmiyor.
-
+ '{0}' öğesine TabPage eklenemez. TabPage'ler yalnızca TabControl'lere eklenebilir.
-
+ Bir TabPage başka bir TabPage'e eklenemez. TabPage'ler yalnızca TabControl'lere eklenebilir.
diff --git a/src/System.Windows.Forms/src/Resources/xlf/SR.zh-Hans.xlf b/src/System.Windows.Forms/src/Resources/xlf/SR.zh-Hans.xlf
index 7a021bd20f4..5f72e45ed7d 100644
--- a/src/System.Windows.Forms/src/Resources/xlf/SR.zh-Hans.xlf
+++ b/src/System.Windows.Forms/src/Resources/xlf/SR.zh-Hans.xlf
@@ -9511,12 +9511,12 @@ Stack trace where the illegal operation occurred was:
此操作系统不支持该功能。
-
+ 无法将 TabPage 添加到“{0}”。 只能将 TabPages 添加到 TabControls。
-
+ 无法将 TabPage 添加到其他 TabPage。 TabPages 只能添加到 TabControls。
diff --git a/src/System.Windows.Forms/src/Resources/xlf/SR.zh-Hant.xlf b/src/System.Windows.Forms/src/Resources/xlf/SR.zh-Hant.xlf
index 49e4c2606c5..56111796c84 100644
--- a/src/System.Windows.Forms/src/Resources/xlf/SR.zh-Hant.xlf
+++ b/src/System.Windows.Forms/src/Resources/xlf/SR.zh-Hant.xlf
@@ -9511,12 +9511,12 @@ Stack trace where the illegal operation occurred was:
此作業系統不支援這項功能。
-
+ 無法將 TabPage 加入 '{0}'。TabPages 只能加入 TabControls。
-
+ 無法將 TabPage 加入其他 TabPage。TabPages 只能加入 TabControls。
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs
index 9e1bff09545..cdc425c75c7 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs
@@ -8128,8 +8128,7 @@ internal virtual void OnInvokedSetScrollPosition(object sender, EventArgs e)
[EditorBrowsable(EditorBrowsableState.Advanced)]
protected virtual void OnLocationChanged(EventArgs e)
{
- OnMove(EventArgs.Empty);
-
+ OnMove(e);
if (Events[EventLocation] is EventHandler eh)
{
eh(this, e);
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/TabPage.cs b/src/System.Windows.Forms/src/System/Windows/Forms/TabPage.cs
index 455812cc183..72cae1d67fc 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/TabPage.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/TabPage.cs
@@ -2,30 +2,27 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+using System.ComponentModel;
+using System.Diagnostics;
+using System.Drawing;
+using System.Drawing.Design;
+using System.Runtime.InteropServices;
+using System.Text;
+using System.Windows.Forms.Layout;
+
namespace System.Windows.Forms
{
- using System.ComponentModel;
- using System.Diagnostics;
- using System;
- using System.Drawing;
- using System.Drawing.Design;
- using System.Text;
- using System.Runtime.InteropServices;
- using System.Windows.Forms.Layout;
-
///
- /// TabPage implements a single page of a tab control. It is essentially
- /// a Panel with TabItem properties.
+ /// TabPage implements a single page of a tab control. It is essentially a Panel with TabItem
+ /// properties.
///
- [
- ComVisible(true),
- ClassInterface(ClassInterfaceType.AutoDispatch),
- Designer("System.Windows.Forms.Design.TabPageDesigner, " + AssemblyRef.SystemDesign),
- ToolboxItem(false),
- DesignTimeVisible(false),
- DefaultEvent("Click"),
- DefaultProperty("Text")
- ]
+ [ComVisible(true)]
+ [ClassInterface(ClassInterfaceType.AutoDispatch)]
+ [Designer("System.Windows.Forms.Design.TabPageDesigner, " + AssemblyRef.SystemDesign)]
+ [ToolboxItem(false)]
+ [DesignTimeVisible(false)]
+ [DefaultEvent("Click")]
+ [DefaultProperty("Text")]
public class TabPage : Panel
{
private ImageList.Indexer imageIndexer;
@@ -37,28 +34,30 @@ public class TabPage : Panel
///
/// Constructs an empty TabPage.
///
- public TabPage()
- : base()
+ public TabPage() : base()
{
SetStyle(ControlStyles.CacheText, true);
Text = null;
}
+ ///
+ /// Constructs a TabPage with text for the tab.
+ ///
+ public TabPage(string text) : this()
+ {
+ Text = text;
+ }
+
///
/// Allows the control to optionally shrink when AutoSize is true.
///
- [
- EditorBrowsable(EditorBrowsableState.Never),
- DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
- Browsable(false),
- Localizable(false)
- ]
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
+ [Browsable(false),]
+ [Localizable(false)]
public override AutoSizeMode AutoSizeMode
{
- get
- {
- return AutoSizeMode.GrowOnly;
- }
+ get => AutoSizeMode.GrowOnly;
set
{
}
@@ -67,52 +66,45 @@ public override AutoSizeMode AutoSizeMode
///
/// Hide AutoSize: it doesn't make sense for this control
///
- [Browsable(false), EditorBrowsable(EditorBrowsableState.Never),
+ [Browsable(false)]
+ [EditorBrowsable(EditorBrowsableState.Never),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public override bool AutoSize
{
- get
- {
- return base.AutoSize;
- }
- set
- {
- base.AutoSize = value;
- }
+ get => base.AutoSize;
+ set => base.AutoSize = value;
}
- [SRCategory(nameof(SR.CatPropertyChanged)), SRDescription(nameof(SR.ControlOnAutoSizeChangedDescr))]
- [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
- new public event EventHandler AutoSizeChanged
+ [SRCategory(nameof(SR.CatPropertyChanged))]
+ [SRDescription(nameof(SR.ControlOnAutoSizeChangedDescr))]
+ [Browsable(false)]
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public new event EventHandler AutoSizeChanged
{
add => base.AutoSizeChanged += value;
remove => base.AutoSizeChanged -= value;
}
///
- /// The background color of this control. This is an ambient property and
- /// will always return a non-null value.
+ /// The background color of this control. This is an ambient property and will always return
+ /// a non-null value.
///
- [
- SRCategory(nameof(SR.CatAppearance)),
- SRDescription(nameof(SR.ControlBackColorDescr))
- ]
+ [SRCategory(nameof(SR.CatAppearance))]
+ [SRDescription(nameof(SR.ControlBackColorDescr))]
public override Color BackColor
{
get
{
Color color = base.BackColor;
- // If some color is Set by the user return that...
if (color != DefaultBackColor)
{
return color;
}
- // If user has not set a color and if theming ON and Parent's appearance is Normal, then return the Transparent Color....
- if (Application.RenderWithVisualStyles && UseVisualStyleBackColor && (ParentInternal is TabControl parent && parent.Appearance == TabAppearance.Normal))
+ else if (Application.RenderWithVisualStyles && UseVisualStyleBackColor && (ParentInternal is TabControl parent && parent.Appearance == TabAppearance.Normal))
{
return Color.Transparent;
}
- // return base.Color by default...
+
return color;
}
set
@@ -139,51 +131,30 @@ public override Color BackColor
}
///
- /// Constructs the new instance of the Controls collection objects. Subclasses
- /// should not call base.CreateControlsInstance. Our version creates a control
- /// collection that does not support
+ /// Constructs the new instance of the Controls collection objects.
///
- protected override ControlCollection CreateControlsInstance()
- {
- return new TabPageControlCollection(this);
- }
-
- internal ImageList.Indexer ImageIndexer
- {
- get
- {
- if (imageIndexer == null)
- {
- imageIndexer = new ImageList.Indexer();
- }
+ protected override ControlCollection CreateControlsInstance() => new TabPageControlCollection(this);
- return imageIndexer;
- }
- }
+ internal ImageList.Indexer ImageIndexer => imageIndexer ??= new ImageList.Indexer();
///
- /// Returns the imageIndex for the tabPage. This should point to an image
+ /// Returns the imageIndex for the TabPage. This should point to an image
/// in the TabControl's associated imageList that will appear on the tab, or be -1.
///
- [
- TypeConverter(typeof(ImageIndexConverter)),
- Editor("System.Windows.Forms.Design.ImageIndexEditor, " + AssemblyRef.SystemDesign, typeof(UITypeEditor)),
- Localizable(true),
- RefreshProperties(RefreshProperties.Repaint),
- DefaultValue(-1),
- SRDescription(nameof(SR.TabItemImageIndexDescr))
- ]
+ [TypeConverter(typeof(ImageIndexConverter))]
+ [Editor("System.Windows.Forms.Design.ImageIndexEditor, " + AssemblyRef.SystemDesign, typeof(UITypeEditor))]
+ [Localizable(true)]
+ [RefreshProperties(RefreshProperties.Repaint)]
+ [DefaultValue(-1)]
+ [SRDescription(nameof(SR.TabItemImageIndexDescr))]
public int ImageIndex
{
- get
- {
- return ImageIndexer.Index;
- }
+ get => ImageIndexer.Index;
set
{
if (value < -1)
{
- throw new ArgumentOutOfRangeException(nameof(value), string.Format(SR.InvalidLowBoundArgumentEx, nameof(ImageIndex), value, -1));
+ throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidLowBoundArgumentEx, nameof(ImageIndex), value, -1));
}
if (ParentInternal is TabControl parent)
@@ -197,23 +168,18 @@ public int ImageIndex
}
///
- /// Returns the imageIndex for the tabPage. This should point to an image
- /// in the TabControl's associated imageList that will appear on the tab, or be -1.
+ /// Returns the imageIndex for the TabPage. This should point to an image in the TabControl's
+ /// associated imageList that will appear on the tab, or be -1.
///
- [
- TypeConverter(typeof(ImageKeyConverter)),
- Editor("System.Windows.Forms.Design.ImageIndexEditor, " + AssemblyRef.SystemDesign, typeof(UITypeEditor)),
- Localizable(true),
- DefaultValue(""),
- RefreshProperties(RefreshProperties.Repaint),
- SRDescription(nameof(SR.TabItemImageIndexDescr))
- ]
+ [TypeConverter(typeof(ImageKeyConverter))]
+ [Editor("System.Windows.Forms.Design.ImageIndexEditor, " + AssemblyRef.SystemDesign, typeof(UITypeEditor))]
+ [Localizable(true)]
+ [DefaultValue("")]
+ [RefreshProperties(RefreshProperties.Repaint)]
+ [SRDescription(nameof(SR.TabItemImageIndexDescr))]
public string ImageKey
{
- get
- {
- return ImageIndexer.Key;
- }
+ get => ImageIndexer.Key;
set
{
ImageIndexer.Key = value;
@@ -227,198 +193,151 @@ public string ImageKey
}
}
- ///
- /// Constructs a TabPage with text for the tab.
- ///
- public TabPage(string text) : this()
- {
- Text = text;
- }
-
- [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
+ [Browsable(false)]
+ [EditorBrowsable(EditorBrowsableState.Never)]
public override AnchorStyles Anchor
{
- get
- {
- return base.Anchor;
- }
- set
- {
- base.Anchor = value;
- }
+ get => base.Anchor;
+ set => base.Anchor = value;
}
- [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
+ [Browsable(false)]
+ [EditorBrowsable(EditorBrowsableState.Never)]
public override DockStyle Dock
{
- get
- {
- return base.Dock;
- }
- set
- {
- base.Dock = value;
- }
+ get => base.Dock;
+ set => base.Dock = value;
}
- [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
- new public event EventHandler DockChanged
+ [Browsable(false)]
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public new event EventHandler DockChanged
{
add => base.DockChanged += value;
remove => base.DockChanged -= value;
}
- [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
- new public bool Enabled
+ [Browsable(false)]
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public new bool Enabled
{
- get
- {
- return base.Enabled;
- }
- set
- {
- base.Enabled = value;
- }
+ get => base.Enabled;
+ set => base.Enabled = value;
}
- [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
- new public event EventHandler EnabledChanged
+ [Browsable(false)]
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public new event EventHandler EnabledChanged
{
add => base.EnabledChanged += value;
remove => base.EnabledChanged -= value;
}
- [
- DefaultValue(false),
- SRCategory(nameof(SR.CatAppearance)),
- SRDescription(nameof(SR.TabItemUseVisualStyleBackColorDescr))
- ]
+ [DefaultValue(false)]
+ [SRCategory(nameof(SR.CatAppearance))]
+ [SRDescription(nameof(SR.TabItemUseVisualStyleBackColorDescr))]
public bool UseVisualStyleBackColor
{
- get
- {
- return useVisualStyleBackColor;
- }
+ get => useVisualStyleBackColor;
set
{
+ if (useVisualStyleBackColor == value)
+ {
+ return;
+ }
+
useVisualStyleBackColor = value;
Invalidate(true);
}
}
- // Make the Location property non-browsable for the TabPages.
- [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
- new public Point Location
+ ///
+ /// Make the Location property non-browsable for the tab pages.
+ ///
+ [Browsable(false)]
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public new Point Location
{
- get
- {
- return base.Location;
- }
- set
- {
- base.Location = value;
- }
+ get => base.Location;
+ set => base.Location = value;
}
- [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
- new public event EventHandler LocationChanged
+ [Browsable(false)]
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public new event EventHandler LocationChanged
{
add => base.LocationChanged += value;
remove => base.LocationChanged -= value;
}
[DefaultValue(typeof(Size), "0, 0")]
- [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
+ [Browsable(false)]
+ [EditorBrowsable(EditorBrowsableState.Never)]
public override Size MaximumSize
{
- get { return base.MaximumSize; }
+ get => base.MaximumSize;
- set
- {
- base.MaximumSize = value;
- }
+ set => base.MaximumSize = value;
}
- [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
+ [Browsable(false)]
+ [EditorBrowsable(EditorBrowsableState.Never)]
public override Size MinimumSize
{
- get { return base.MinimumSize; }
+ get => base.MinimumSize;
- set
- {
- base.MinimumSize = value;
- }
+ set => base.MinimumSize = value;
}
- [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
- public new Size PreferredSize
- {
- get { return base.PreferredSize; }
- }
+ [Browsable(false)]
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public new Size PreferredSize => base.PreferredSize;
- [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
- new public int TabIndex
+ [Browsable(false)]
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public new int TabIndex
{
- get
- {
- return base.TabIndex;
- }
- set
- {
- base.TabIndex = value;
- }
+ get => base.TabIndex;
+ set => base.TabIndex = value;
}
///
- /// This property is required by certain controls (TabPage) to render its transparency using theming API.
- /// We dont want all controls (that are have transparent BackColor) to use theming API to render its background because it has HUGE PERF cost.
+ /// This property is required by certain controls (TabPage) to render its transparency using
+ /// theming API. We dont want all controls (that are have transparent BackColor) to use
+ /// theming API to render its background because it has large performance cost.
///
- internal override bool RenderTransparencyWithVisualStyles
- {
- get
- {
- return true;
- }
- }
+ internal override bool RenderTransparencyWithVisualStyles => true;
- [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
- new public event EventHandler TabIndexChanged
+ [Browsable(false)]
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public new event EventHandler TabIndexChanged
{
add => base.TabIndexChanged += value;
remove => base.TabIndexChanged -= value;
}
- [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
- new public bool TabStop
+ [Browsable(false)]
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public new bool TabStop
{
- get
- {
- return base.TabStop;
- }
- set
- {
- base.TabStop = value;
- }
+ get => base.TabStop;
+ set => base.TabStop = value;
}
- [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
- new public event EventHandler TabStopChanged
+ [Browsable(false)]
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public new event EventHandler TabStopChanged
{
add => base.TabStopChanged += value;
remove => base.TabStopChanged -= value;
}
- [
- Localizable(true),
- Browsable(true),
- EditorBrowsable(EditorBrowsableState.Always)
- ]
+ [Localizable(true)]
+ [Browsable(true)]
+ [EditorBrowsable(EditorBrowsableState.Always)]
public override string Text
{
- get
- {
- return base.Text;
- }
+ get => base.Text;
set
{
base.Text = value;
@@ -426,28 +345,24 @@ public override string Text
}
}
- [Browsable(true), EditorBrowsable(EditorBrowsableState.Always)]
- new public event EventHandler TextChanged
+ [Browsable(true)]
+ [EditorBrowsable(EditorBrowsableState.Always)]
+ public new event EventHandler TextChanged
{
add => base.TextChanged += value;
remove => base.TextChanged -= value;
}
///
- /// The toolTipText for the tab, that will appear when the mouse hovers
- /// over the tab and the TabControl's showToolTips property is true.
+ /// The toolTipText for the tab, that will appear when the mouse hovers over the tab and the
+ /// TabControl's showToolTips property is true.
///
- [
- DefaultValue(""),
- Localizable(true),
- SRDescription(nameof(SR.TabItemToolTipTextDescr))
- ]
+ [DefaultValue("")]
+ [Localizable(true)]
+ [SRDescription(nameof(SR.TabItemToolTipTextDescr))]
public string ToolTipText
{
- get
- {
- return toolTipText;
- }
+ get => toolTipText;
set
{
if (value == null)
@@ -465,53 +380,47 @@ public string ToolTipText
}
}
- [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
- new public bool Visible
+ [Browsable(false)]
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public new bool Visible
{
- get
- {
- return base.Visible;
- }
- set
- {
- base.Visible = value;
- }
+ get => base.Visible;
+ set => base.Visible = value;
}
- [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
- new public event EventHandler VisibleChanged
+ [Browsable(false)]
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public new event EventHandler VisibleChanged
{
add => base.VisibleChanged += value;
remove => base.VisibleChanged -= value;
}
///
- /// Assigns a new parent control. Sends out the appropriate property change
- /// notifications for properties that are affected by the change of parent.
+ /// Assigns a new parent control. Sends out the appropriate property change notifications for
+ /// properties that are affected by the change of parent.
///
internal override void AssignParent(Control value)
{
if (value != null && !(value is TabControl))
{
- throw new ArgumentException(string.Format(SR.TABCONTROLTabPageNotOnTabControl, value.GetType().FullName));
+ throw new ArgumentException(string.Format(SR.TabControlTabPageNotOnTabControl, value.GetType().FullName));
}
base.AssignParent(value);
}
///
- /// Given a component, this retrieves the tab page that it's parented to, or
- /// null if it's not parented to any tab page.
+ /// Given a component, this retrieves the tab page that it's parented to, or null if it's not
+ /// parented to any tab page.
///
public static TabPage GetTabPageOfComponent(object comp)
{
- if (!(comp is Control))
+ if (!(comp is Control c))
{
return null;
}
- Control c = (Control)comp;
-
while (c != null && !(c is TabPage))
{
c = c.ParentInternal;
@@ -553,32 +462,27 @@ private void PrefixAmpersands(ref string value)
// text string, but the accelerators don't work.
// So in this function, we prefix ampersands with another ampersand
// so that they actually appear as ampersands.
- //
- // Sanity check parameter
- //
- if (value == null || value.Length == 0)
+ if (string.IsNullOrEmpty(value))
{
return;
}
// If there are no ampersands, we don't need to do anything here
- //
if (value.IndexOf('&') < 0)
{
return;
}
// Insert extra ampersands
- //
- StringBuilder newString = new StringBuilder();
-
+ var newString = new StringBuilder();
for (int i = 0; i < value.Length; ++i)
{
if (value[i] == '&')
{
if (i < value.Length - 1 && value[i + 1] == '&')
{
- ++i; // Skip the second ampersand
+ // Skip the second ampersand
+ ++i;
}
newString.Append("&&");
@@ -593,7 +497,7 @@ private void PrefixAmpersands(ref string value)
}
///
- /// This is an internal method called by the TabControl to fire the Leave event when TabControl leave occurs.
+ /// This is an internal method called by the TabControl to fire the Leave event when TabControl leave occurs.
///
internal void FireLeave(EventArgs e)
{
@@ -602,7 +506,7 @@ internal void FireLeave(EventArgs e)
}
///
- /// This is an internal method called by the TabControl to fire the Enter event when TabControl leave occurs.
+ /// This is an internal method called by the TabControl to fire the Enter event when TabControl leave occurs.
///
internal void FireEnter(EventArgs e)
{
@@ -611,14 +515,12 @@ internal void FireEnter(EventArgs e)
}
///
- /// Actually goes and fires the OnEnter event. Inheriting controls
- /// should use this to know when the event is fired [this is preferable to
- /// adding an event handler on yourself for this event]. They should,
- /// however, remember to call base.OnEnter(e); to ensure the event is
- /// still fired to external listeners
- /// This listener is overidden so that we can fire SAME ENTER and LEAVE
- /// events on the TabPage.
- /// TabPage should fire enter when the focus is on the TABPAGE and not when the control
+ /// Actually goes and fires the OnEnter event. Inheriting controls should use this to know
+ /// when the event is fired [this is preferable to adding an event handler on yourself for
+ /// this event]. They should, however, remember to call base.OnEnter(e); to ensure the event
+ /// i still fired to external listeners
+ /// This listener is overidden so that we can fire SAME ENTER and LEAVE events on the TabPage.
+ /// TabPage should fire enter when the focus is on the TabPage and not when the control
/// within the TabPage gets Focused.
///
protected override void OnEnter(EventArgs e)
@@ -635,17 +537,14 @@ protected override void OnEnter(EventArgs e)
}
///
- /// Actually goes and fires the OnLeave event. Inheriting controls
- /// should use this to know when the event is fired [this is preferable to
- /// adding an event handler on yourself for this event]. They should,
- /// however, remember to call base.OnLeave(e); to ensure the event is
- /// still fired to external listeners
- /// This listener is overidden so that we can fire SAME ENTER and LEAVE
- /// events on the TabPage.
- /// TabPage should fire enter when the focus is on the TABPAGE and not when the control
- /// within the TabPage gets Focused.
- /// Similary the Leave should fire when the TabControl (and hence the TabPage) looses
- /// Focus.
+ /// Actually goes and fires the OnLeave event. Inheriting controls should use this to know
+ /// when the event is fired [this is preferable to adding an event handler on yourself for
+ /// this event]. They should, however, remember to call base.OnLeave(e); to ensure the event
+ /// is still fired to external listeners
+ /// This listener is overidden so that we can fire same enter and leave events on the TabPage.
+ /// TabPage should fire enter when the focus is on the TabPage and not when the control within
+ /// the TabPage gets Focused.
+ /// Similary the Leave should fire when the TabControl (and hence the TabPage) loses focus.
///
protected override void OnLeave(EventArgs e)
{
@@ -662,35 +561,26 @@ protected override void OnLeave(EventArgs e)
protected override void OnPaintBackground(PaintEventArgs e)
{
- // Utilize the TabRenderer new to Whidbey to draw the tab pages so that the
- // panels are drawn using the correct visual styles when the application supports using visual
+ // Utilize the TabRenderer new to Whidbey to draw the tab pages so that the panels are
+ // drawn using the correct visual styles when the application supports using visual
// styles.
- // Does this application utilize Visual Styles?
- // Utilize the UseVisualStyleBackColor property to determine whether or
- // not the themed background should be utilized.
+ // Utilize the UseVisualStyleBackColor property to determine whether or not the themed
+ // background should be utilized.
if (Application.RenderWithVisualStyles && UseVisualStyleBackColor && (ParentInternal is TabControl parent && parent.Appearance == TabAppearance.Normal))
{
-
Color bkcolor = UseVisualStyleBackColor ? Color.Transparent : BackColor;
Rectangle inflateRect = LayoutUtils.InflateRect(DisplayRectangle, Padding);
- //To ensure that the tabpage draws correctly (the border will get clipped and
- // and gradient fill will match correctly with the tabcontrol). Unfortunately, there is no good way to determine
- // the padding used on the tabpage.
- // I would like to use the following below, but GetMargins is busted in the theming API:
- //VisualStyleRenderer visualStyleRenderer = new VisualStyleRenderer(VisualStyleElement.Tab.Pane.Normal);
- //Padding themePadding = visualStyleRenderer.GetMargins(e.Graphics, MarginProperty.ContentMargins);
- //Rectangle rectWithBorder = new Rectangle(inflateRect.X - themePadding.Left,
- // inflateRect.Y - themePadding.Top,
- // inflateRect.Width + themePadding.Right + themePadding.Left,
- // inflateRect.Height + themePadding.Bottom + themePadding.Top);
+ // To ensure that the TabPage draws correctly (the border will get clipped and
+ // and gradient fill will match correctly with the tabcontrol). Unfortunately,
+ // there is no good way to determine the padding used on the TabPage.
Rectangle rectWithBorder = new Rectangle(inflateRect.X - 4, inflateRect.Y - 2, inflateRect.Width + 8, inflateRect.Height + 6);
TabRenderer.DrawTabPage(e.Graphics, rectWithBorder);
- // Is there a background image to paint? The TabRenderer does not currently support
- // painting the background image on the panel, so we need to draw it ourselves.
+ // TabRenderer does not support painting the background image on the panel, so
+ // draw it ourselves.
if (BackgroundImage != null)
{
ControlPaint.DrawBackgroundImage(e.Graphics, BackgroundImage, bkcolor, BackgroundImageLayout, inflateRect, inflateRect, DisplayRectangle.Location);
@@ -703,8 +593,8 @@ protected override void OnPaintBackground(PaintEventArgs e)
}
///
- /// overrides main setting of our bounds so that we can control our size and that of our
- /// TabPages...
+ /// Overrides main setting of our bounds so that we can control our size and that of our
+ /// TabPages.
///
protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified)
{
@@ -715,7 +605,7 @@ protected override void SetBoundsCore(int x, int y, int width, int height, Bound
Rectangle r = parent.DisplayRectangle;
// LayoutEngines send BoundsSpecified.None so they can know they are the ones causing the size change
- // in the subsequent InitLayout. We need to be careful preserve a None.
+ // in the subsequent InitLayout. We need to be careful preserve a None.
base.SetBoundsCore(r.X, r.Y, r.Width, r.Height, specified == BoundsSpecified.None ? BoundsSpecified.None : BoundsSpecified.All);
}
else
@@ -728,18 +618,12 @@ protected override void SetBoundsCore(int x, int y, int width, int height, Bound
/// Determines if the Location property needs to be persisted.
///
[EditorBrowsable(EditorBrowsableState.Never)]
- private bool ShouldSerializeLocation()
- {
- return Left != 0 || Top != 0;
- }
+ private bool ShouldSerializeLocation() => Left != 0 || Top != 0;
///
/// The text property is what is returned for the TabPages default printing.
///
- public override string ToString()
- {
- return "TabPage: {" + Text + "}";
- }
+ public override string ToString() => $"TabPage: {{{Text}}}";
internal void UpdateParent()
{
@@ -765,7 +649,7 @@ public TabPageControlCollection(TabPage owner) : base(owner)
///
/// Adds a child control to this control. The control becomes the last control
/// in the child control list. If the control is already a child of another
- /// control it is first removed from that control. The tab page overrides
+ /// control it is first removed from that control. The tab page overrides
/// this method to ensure that child tab pages are not added to it, as these
/// are illegal.
///
@@ -773,7 +657,7 @@ public override void Add(Control value)
{
if (value is TabPage)
{
- throw new ArgumentException(SR.TABCONTROLTabPageOnTabPage);
+ throw new ArgumentException(SR.TabControlTabPageOnTabPage);
}
base.Add(value);
@@ -781,4 +665,3 @@ public override void Add(Control value)
}
}
}
-
diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ControlTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ControlTests.cs
index da94f44a874..2e62bf5b9c5 100644
--- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ControlTests.cs
+++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ControlTests.cs
@@ -1890,7 +1890,7 @@ public void Control_TopGetSet(int expected)
[Theory]
[CommonMemberData(nameof(CommonTestHelper.GetPointTheoryData))]
- public void Control_LocationGetSet(Point value)
+ public void Control_Location_Set_GetReturnsExpected(Point value)
{
var control = new Control
{
@@ -1903,6 +1903,131 @@ public void Control_LocationGetSet(Point value)
Assert.Equal(value, control.Location);
}
+ [Theory]
+ [CommonMemberData(nameof(CommonTestHelper.GetPointTheoryData))]
+ public void Control_Location_SetWithParent_GetReturnsExpected(Point value)
+ {
+ var parent = new Control();
+ var control = new Control
+ {
+ Parent = parent,
+ Location = value
+ };
+ Assert.Equal(value, control.Location);
+
+ // Set same.
+ control.Location = value;
+ Assert.Equal(value, control.Location);
+ }
+
+ [Fact]
+ public void Control_Location_SetWithHandle_DoesNotCallInvalidate()
+ {
+ var control = new Control();
+ Assert.NotEqual(IntPtr.Zero, control.Handle);
+ int invalidatedCallCount = 0;
+ control.Invalidated += (sender, e) => invalidatedCallCount++;
+
+ // Set different.
+ control.Location = new Point(1, 2);
+ Assert.Equal(new Point(1, 2), control.Location);
+ Assert.Equal(0, invalidatedCallCount);
+
+ // Set same.
+ control.Location = new Point(1, 2);
+ Assert.Equal(new Point(1, 2), control.Location);
+ Assert.Equal(0, invalidatedCallCount);
+
+ // Set different.
+ control.Location = new Point(2, 3);
+ Assert.Equal(new Point(2, 3), control.Location);
+ Assert.Equal(0, invalidatedCallCount);
+ }
+
+ [Theory]
+ [InlineData(true, 1)]
+ [InlineData(false, 0)]
+ public void Control_Location_SetWithHandleWithTransparentBackColor_DoesNotCallInvalidate(bool supportsTransparentBackgroundColor, int expectedInvalidatedCallCount)
+ {
+ var control = new SubControl();
+ control.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
+ control.BackColor = Color.FromArgb(254, 255, 255, 255);
+ control.SetStyle(ControlStyles.SupportsTransparentBackColor, supportsTransparentBackgroundColor);
+
+ Assert.NotEqual(IntPtr.Zero, control.Handle);
+ int invalidatedCallCount = 0;
+ control.Invalidated += (sender, e) => invalidatedCallCount++;
+
+ // Set different.
+ control.Location = new Point(1, 2);
+ Assert.Equal(new Point(1, 2), control.Location);
+ Assert.Equal(expectedInvalidatedCallCount, invalidatedCallCount);
+
+ // Set same.
+ control.Location = new Point(1, 2);
+ Assert.Equal(new Point(1, 2), control.Location);
+ Assert.Equal(expectedInvalidatedCallCount, invalidatedCallCount);
+
+ // Set different.
+ control.Location = new Point(2, 3);
+ Assert.Equal(new Point(2, 3), control.Location);
+ Assert.Equal(expectedInvalidatedCallCount * 2, invalidatedCallCount);
+ }
+
+ [Fact]
+ public void Control_Location_SetWithHandler_CallsLocationChanged()
+ {
+ var control = new Control();
+ int locationChangedCallCount = 0;
+ EventHandler locationChangedHandler = (sender, e) =>
+ {
+ Assert.Same(control, sender);
+ Assert.Same(EventArgs.Empty, e);
+ locationChangedCallCount++;
+ };
+ control.LocationChanged += locationChangedHandler;
+ int moveCallCount = 0;
+ EventHandler moveHandler = (sender, e) =>
+ {
+ Assert.Same(control, sender);
+ Assert.Same(EventArgs.Empty, e);
+ moveCallCount++;
+ };
+ control.Move += moveHandler;
+
+ // Set different.
+ control.Location = new Point(1, 2);
+ Assert.Equal(new Point(1, 2), control.Location);
+ Assert.Equal(1, locationChangedCallCount);
+ Assert.Equal(1, moveCallCount);
+
+ // Set same.
+ control.Location = new Point(1, 2);
+ Assert.Equal(new Point(1, 2), control.Location);
+ Assert.Equal(1, locationChangedCallCount);
+ Assert.Equal(1, moveCallCount);
+
+ // Set different x.
+ control.Location = new Point(2, 2);
+ Assert.Equal(new Point(2, 2), control.Location);
+ Assert.Equal(2, locationChangedCallCount);
+ Assert.Equal(2, moveCallCount);
+
+ // Set different y.
+ control.Location = new Point(2, 3);
+ Assert.Equal(new Point(2, 3), control.Location);
+ Assert.Equal(3, locationChangedCallCount);
+ Assert.Equal(3, moveCallCount);
+
+ // Remove handler.
+ control.LocationChanged -= locationChangedHandler;
+ control.Move -= moveHandler;
+ control.Location = new Point(1, 2);
+ Assert.Equal(new Point(1, 2), control.Location);
+ Assert.Equal(3, locationChangedCallCount);
+ Assert.Equal(3, moveCallCount);
+ }
+
[Theory]
[CommonMemberData(nameof(CommonTestHelper.GetPaddingNormalizedTheoryData))]
public void Control_Margin_Set_GetReturnsExpected(Padding value, Padding expected)
@@ -2149,18 +2274,6 @@ public void Control_ControlAddedAndRemoved()
Assert.True(wasRemoved);
}
- [Fact]
- public void Control_LocationChanged()
- {
- bool wasChanged = false;
- var cont = new Control();
- cont.LocationChanged += (sender, args) => wasChanged = true;
-
- cont.Location = new Point(1, 1);
-
- Assert.True(wasChanged);
- }
-
[Theory]
[CommonMemberData(nameof(CommonTestHelper.GetFontTheoryData))]
public void Control_Font_Set_GetReturnsExpected(Font value)
@@ -4005,26 +4118,135 @@ public void Control_OnLayout_Invoke_CallsLayout(LayoutEventArgs eventArgs)
[Theory]
[CommonMemberData(nameof(CommonTestHelper.GetEventArgsTheoryData))]
- public void Control_OnLeave_Invoke_CallsLeave(EventArgs eventArgs)
+ public void Control_OnLocationChanged_Invoke_CallsLocationChangedAndMove(EventArgs eventArgs)
{
var control = new SubControl();
- int callCount = 0;
- EventHandler handler = (sender, e) =>
+ int locationChangedCallCount = 0;
+ EventHandler locationChangedHandler = (sender, e) =>
{
Assert.Same(control, sender);
Assert.Same(eventArgs, e);
- callCount++;
+ locationChangedCallCount++;
+ };
+ int moveCallCount = 0;
+ EventHandler moveHandler = (sender, e) =>
+ {
+ Assert.Same(control, sender);
+ Assert.Same(eventArgs, e);
+ moveCallCount++;
};
// Call with handler.
- control.Leave += handler;
- control.OnLeave(eventArgs);
- Assert.Equal(1, callCount);
+ control.LocationChanged += locationChangedHandler;
+ control.Move += moveHandler;
+ control.OnLocationChanged(eventArgs);
+ Assert.Equal(1, locationChangedCallCount);
+ Assert.Equal(1, moveCallCount);
// Remove handler.
- control.Leave -= handler;
- control.OnLeave(eventArgs);
- Assert.Equal(1, callCount);
+ control.LocationChanged -= locationChangedHandler;
+ control.Move -= moveHandler;
+ control.OnLocationChanged(eventArgs);
+ Assert.Equal(1, locationChangedCallCount);
+ Assert.Equal(1, moveCallCount);
+ }
+
+ [Theory]
+ [CommonMemberData(nameof(CommonTestHelper.GetEventArgsTheoryData))]
+ public void Control_OnLocationChanged_InvokeWithHandle_CallsLocationChangedAndMove(EventArgs eventArgs)
+ {
+ var control = new SubControl();
+ Assert.NotEqual(IntPtr.Zero, control.Handle);
+
+ int locationChangedCallCount = 0;
+ EventHandler locationChangedHandler = (sender, e) =>
+ {
+ Assert.Same(control, sender);
+ Assert.Same(eventArgs, e);
+ locationChangedCallCount++;
+ };
+ int moveCallCount = 0;
+ EventHandler moveHandler = (sender, e) =>
+ {
+ Assert.Same(control, sender);
+ Assert.Same(eventArgs, e);
+ moveCallCount++;
+ };
+ int invalidatedCallCount = 0;
+ InvalidateEventHandler invalidatedHandler = (sender, e) => invalidatedCallCount++;
+
+ // Call with handler.
+ control.LocationChanged += locationChangedHandler;
+ control.Move += moveHandler;
+ control.Invalidated += invalidatedHandler;
+ control.OnLocationChanged(eventArgs);
+ Assert.Equal(1, locationChangedCallCount);
+ Assert.Equal(1, moveCallCount);
+ Assert.Equal(0, invalidatedCallCount);
+
+ // Remove handler.
+ control.LocationChanged -= locationChangedHandler;
+ control.Move -= moveHandler;
+ control.Invalidated -= invalidatedHandler;
+ control.OnLocationChanged(eventArgs);
+ Assert.Equal(1, locationChangedCallCount);
+ Assert.Equal(1, moveCallCount);
+ Assert.Equal(0, invalidatedCallCount);
+ }
+
+ public static IEnumerable