Ban `Control.Focus`

"Focus is a low-level method intended primarily for custom control
authors. Instead, application programmers should use the Select method
or the ActiveControl property for child controls, or the Activate method
for forms." --MSDN
This commit is contained in:
YoshiRulz 2024-08-25 23:45:44 +10:00
parent 2dd87d78f9
commit 8e12e44411
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
12 changed files with 18 additions and 16 deletions

View File

@ -9,3 +9,4 @@ M:System.Convert.ToSingle(System.String);use float.{Try,}Parse
M:System.Convert.ToUInt16(System.String);use ushort.{Try,}Parse
M:System.Convert.ToUInt32(System.String);use uint.{Try,}Parse
M:System.Convert.ToUInt64(System.String);use ulong.{Try,}Parse
M:System.Windows.Forms.Control.Focus;use Activate for Forms, or Select otherwise

View File

@ -228,7 +228,9 @@ namespace BizHawk.Client.EmuHawk
switch (m.Msg)
{
case 0x0201: // WM_LBUTTONDOWN
#pragma warning disable RS0030 //TODO is this correct, or should it be `Select()`? --yoshi
Focus();
#pragma warning restore RS0030
return;
case 0x0203: // WM_LBUTTONDBLCLK
case 0x0204: // WM_RBUTTONDOWN

View File

@ -18,7 +18,7 @@ namespace BizHawk.Client.EmuHawk
_config = config;
InitializeComponent();
Icon = Properties.Resources.HotKeysIcon;
tabPage1.Focus();
tabPage1.Select();
}
protected override void OnActivated(EventArgs e)
@ -189,7 +189,7 @@ namespace BizHawk.Client.EmuHawk
{
foreach (var c in HotkeyTabControl.SelectedTab.Controls.OfType<InputWidget>())
{
c.Focus();
c.Select();
return;
}
}
@ -208,7 +208,7 @@ namespace BizHawk.Client.EmuHawk
if (w != null)
{
HotkeyTabControl.SelectTab((TabPage)w.Parent);
w.Focus();
w.Select();
}
}

View File

@ -610,7 +610,7 @@ namespace BizHawk.Client.EmuHawk
{
if (!_programmaticallyChangingStopFrameCheckbox)
{
StopOnFrameTextBox.Focus();
StopOnFrameTextBox.Select();
}
}

View File

@ -46,7 +46,7 @@ namespace BizHawk.Client.EmuHawk
DurationNumeric.Value = Sub.Duration;
colorDialog1.Color = Color.FromArgb((int)Sub.Color);
ColorPanel.BackColor = colorDialog1.Color;
Message.Focus();
Message.Select();
}
private void ColorPanel_DoubleClick(object sender, EventArgs e)

View File

@ -1500,7 +1500,7 @@ namespace BizHawk.Client.EmuHawk
else
{
_hexFind.InitialValue = _findStr;
_hexFind.Focus();
_hexFind.Activate();
}
}

View File

@ -40,7 +40,6 @@ namespace BizHawk.Client.EmuHawk
TextRadio.Select();
}
FindBox.Focus();
FindBox.Select();
}

View File

@ -1074,7 +1074,7 @@ namespace BizHawk.Client.EmuHawk
if (form is LuaRegisteredFunctionsList)
{
alreadyOpen = true;
form.Focus();
form.Activate();
}
}

View File

@ -48,7 +48,7 @@ namespace BizHawk.Client.EmuHawk
.ThenBy(l => l.Name)
.ToList();
UpdateList();
FilterBox.Focus();
FilterBox.Select();
ToWikiMarkupButton.Visible = VersionInfo.DeveloperBuild;
}

View File

@ -61,7 +61,7 @@
{
if (!MainForm.GameIsClosing)
{
Focus();
Activate();
_suppressAskSave = suppressSave;
NewTasMenuItem_Click(null, null);
_suppressAskSave = false;

View File

@ -510,7 +510,7 @@ namespace BizHawk.Client.EmuHawk
{
if (ContainsFocus)
{
TasView.Focus();
TasView.Select();
}
}

View File

@ -1464,7 +1464,7 @@ namespace BizHawk.Client.EmuHawk
if (Focused)
{
SpecificValueBox.Focus();
SpecificValueBox.Select();
}
SpecificAddressBox.Enabled = false;
@ -1486,7 +1486,7 @@ namespace BizHawk.Client.EmuHawk
if (Focused)
{
SpecificAddressBox.Focus();
SpecificAddressBox.Select();
}
NumberOfChangesBox.Enabled = false;
@ -1508,7 +1508,7 @@ namespace BizHawk.Client.EmuHawk
if (Focused)
{
NumberOfChangesBox.Focus();
NumberOfChangesBox.Select();
}
DifferenceBox.Enabled = false;
@ -1530,7 +1530,7 @@ namespace BizHawk.Client.EmuHawk
if (Focused)
{
DifferenceBox.Focus();
DifferenceBox.Select();
}
SetCompareTo(Compare.Difference);
@ -1590,7 +1590,7 @@ namespace BizHawk.Client.EmuHawk
if (Focused)
{
DifferentByBox.Focus();
DifferentByBox.Select();
}
SetComparisonOperator(ComparisonOperator.DifferentBy);