8000 Modernize the rest of the event hooks by JeremyKuhne · Pull Request #11852 · dotnet/winforms · GitHub
[go: up one dir, main page]

Skip to content

Modernize the rest of the event hooks #11852

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void AnimateAndCaptureFrames()
Directory.CreateDirectory(testOutputFolder);
frameIndexes[imageName] = 0;

handlers[imageName] = new EventHandler(new Action<object, EventArgs>((object o, EventArgs e) =>
handlers[imageName] = new(new Action<object, EventArgs>((object o, EventArgs e) =>
{
Bitmap animation = (Bitmap)o;
ImageAnimator.UpdateFrames(animation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ private void InitializeComponent()
_buttonOK.MinimumSize = new Size(75, 23);
_buttonOK.Name = "buttonOK";
_buttonOK.Padding = new Padding(10, 0, 10, 0);
_buttonOK.Click += new EventHandler(ButtonOK_click);
_buttonOK.Click += ButtonOK_click;
//
// buttonSave
//
Expand All @@ -195,7 +195,7 @@ private void InitializeComponent()
_buttonSave.MinimumSize = new Size(75, 23);
_buttonSave.Name = "buttonSave";
_buttonSave.Padding = new Padding(10, 0, 10, 0);
_buttonSave.Click += new EventHandler(ButtonSave_click);
_buttonSave.Click += ButtonSave_click;
//
// groupBoxMode
//
Expand Down Expand Up @@ -227,29 +227,29 @@ private void InitializeComponent()
resources.ApplyResources(_radioUnicode, "radioUnicode");
_radioUnicode.Margin = new Padding(3, 0, 0, 0);
_radioUnicode.Name = "radioUnicode";
_radioUnicode.CheckedChanged += new EventHandler(RadioUnicode_checkedChanged);
_radioUnicode.CheckedChanged += RadioUnicode_checkedChanged;
//
// radioAuto
//
resources.ApplyResources(_radioAuto, "radioAuto");
_radioAuto.Checked = true;
_radioAuto.Margin = new Padding(0, 0, 3, 0);
_radioAuto.Name = "radioAuto";
_radioAuto.CheckedChanged += new EventHandler(RadioAuto_checkedChanged);
_radioAuto.CheckedChanged += RadioAuto_checkedChanged;
//
// radioAnsi
//
resources.ApplyResources(_radioAnsi, "radioAnsi");
_radioAnsi.Margin = new Padding(3, 0, 3, 0);
_radioAnsi.Name = "radioAnsi";
_radioAnsi.CheckedChanged += new EventHandler(RadioAnsi_checkedChanged);
_radioAnsi.CheckedChanged += RadioAnsi_checkedChanged;
//
// radioHex
//
resources.ApplyResources(_radioHex, "radioHex");
_radioHex.Margin = new Padding(3, 0, 3, 0);
_radioHex.Name = "radioHex";
_radioHex.CheckedChanged += new EventHandler(RadioHex_checkedChanged);
_radioHex.CheckedChanged += RadioHex_checkedChanged;
//
// okSaveTableLayoutPanel
//
Expand Down Expand Up @@ -290,8 +290,8 @@ private void InitializeComponent()
Name = "BinaryUI";
ShowIcon = false;
ShowInTaskbar = false;
HelpRequested += new HelpEventHandler(Form_HelpRequested);
HelpButtonClicked += new CancelEventHandler(Form_HelpButtonClicked);
HelpRequested += Form_HelpRequested;
HelpButtonClicked += Form_HelpButtonClicked;
_byteViewer.ResumeLayout(false);
_byteViewer.PerformLayout();
_groupBoxMode.ResumeLayout(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,12 +437,14 @@ private void InitUI()
{
_scrollbarHeight = SystemInformation.HorizontalScrollBarHeight;
_scrollbarWidth = SystemInformation.VerticalScrollBarWidth;

// For backwards compat
Size = new Size(SCROLLBAR_START_X + _scrollbarWidth + BORDER_GAP + INSET_GAP,
2 * (BORDER_GAP + INSET_GAP) + _rowCount * (CELL_HEIGHT));
Size = new Size(
SCROLLBAR_START_X + _scrollbarWidth + BORDER_GAP + INSET_GAP,
2 * (BORDER_GAP + INSET_GAP) + _rowCount * (CELL_HEIGHT));

_scrollBar = new VScrollBar();
_scrollBar.ValueChanged += new EventHandler(ScrollChanged);
_scrollBar.ValueChanged += ScrollChanged;
_scrollBar.TabStop = true;
_scrollBar.TabIndex = 0;
_scrollBar.Dock = DockStyle.Right;
Expand Down Expand Up @@ -557,8 +559,9 @@ protected override void OnLayout(LayoutEventArgs e)
if (Dock == DockStyle.None)
{
// For backwards compatibility
Size = new Size(SCROLLBAR_START_X + _scrollbarWidth + BORDER_GAP + INSET_GAP,
2 * (BORDER_GAP + INSET_GAP) + _rowCount * (CELL_HEIGHT));
Size = new Size(
SCROLLBAR_START_X + _scrollbarWidth + BORDER_GAP + INSET_GAP,
2 * (BORDER_GAP + INSET_GAP) + _rowCount * (CELL_HEIGHT));
}

if (_scrollBar is not null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ private void ShowContextMenuStrip()
State = PushButtonState.Pressed;
if (ContextMenuStrip is not null)
{
ContextMenuStrip.Closed += new ToolStripDropDownClosedEventHandler(ContextMenuStrip_Closed);
ContextMenuStrip.Closed += ContextMenuStrip_Closed;
ContextMenuStrip.Show(this, 0, Height);
}
}
Expand All @@ -271,7 +271,7 @@ private void ContextMenuStrip_Closed(object? sender, ToolStripDropDownClosedEven
{
if (sender is ContextMenuStrip cms)
{
cms.Closed -= new ToolStripDropDownClosedEventHandler(ContextMenuStrip_Closed);
cms.Closed -= ContextMenuStrip_Closed;
}

SetButtonDrawState();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ public virtual void Initialize(IComponent component)

if (TryGetService(out IComponentChangeService? cs))
{
cs.ComponentRename += new ComponentRenameEventHandler(OnComponentRename);
cs.ComponentRename += OnComponentRename;
}

InheritanceAttribute? inheritanceAttribute = InheritanceAttribute;
Expand Down Expand Up @@ -455,7 +455,7 @@ protected virtual void Dispose(bool disposing)
{
if (TryGetService(out IComponentChangeService? cs))
{
cs.ComponentRename -= new ComponentRenameEventHandler(OnComponentRename);
cs.ComponentRename -= OnComponentRename;
}

_component = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public event ActiveDesignSurfaceChangedEventHandler? ActiveDesignSurfaceChanged
IDesignerEventService? eventService = EventService;
10000 if (eventService is not null)
{
eventService.ActiveDesignerChanged += new ActiveDesignerEventHandler(OnActiveDesignerChanged);
eventService.ActiveDesignerChanged += OnActiveDesignerChanged;
}
}

Expand All @@ -110,7 +110,7 @@ public event ActiveDesignSurfaceChangedEventHandler? ActiveDesignSurfaceChanged
IDesignerEventService? eventService = EventService;
if (eventService is not null)
{
eventService.ActiveDesignerChanged -= new ActiveDesignerEventHandler(OnActiveDesignerChanged);
eventService.ActiveDesignerChanged -= OnActiveDesignerChanged;
}
}
}
Expand All @@ -128,7 +128,7 @@ public event DesignSurfaceEventHandler? DesignSurfaceCreated
IDesignerEventService? eventService = EventService;
if (eventService is not null)
{
eventService.DesignerCreated += new DesignerEventHandler(OnDesignerCreated);
eventService.DesignerCreated += OnDesignerCreated;
}
}

Expand All @@ -145,7 +145,7 @@ public event DesignSurfaceEventHandler? DesignSurfaceCreated
IDesignerEventService? eventService = EventService;
if (eventService is not null)
{
eventService.DesignerCreated -= new DesignerEventHandler(OnDesignerCreated);
eventService.DesignerCreated -= OnDesignerCreated;
}
}
}
Expand All @@ -163,7 +163,7 @@ public event DesignSurfaceEventHandler? DesignSurfaceDisposed
IDesignerEventService? eventService = EventService;
if (eventService is not null)
{
eventService.DesignerDisposed += new DesignerEventHandler(OnDesignerDisposed);
eventService.DesignerDisposed += OnDesignerDisposed;
}
}

Expand All @@ -180,7 +180,7 @@ public event DesignSurfaceEventHandler? DesignSurfaceDisposed
IDesignerEventService? eventService = EventService;
if (eventService is not null)
{
eventService.DesignerDisposed -= new DesignerEventHandler(OnDesignerDisposed);
eventService.DesignerDisposed -= OnDesignerDisposed;
}
}
}
Expand All @@ -199,7 +199,7 @@ public event EventHandler? SelectionChanged
IDesignerEventService? eventService = EventService;
if (eventService is not null)
{
eventService.SelectionChanged += new EventHandler(OnSelectionChanged);
eventService.SelectionChanged += OnSelectionChanged;
}
}

Expand All @@ -216,7 +216,7 @@ public event EventHandler? SelectionChanged
IDesignerEventService? eventService = EventService;
if (eventService is not null)
{
eventService.SelectionChanged -= new EventHandler(OnSelectionChanged);
eventService.SelectionChanged -= OnSelectionChanged;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ private CheckBoxPropertyLine(IServiceProvider serviceProvider, DesignerActionPan
UseMnemonic = false,
ForeColor = ActionPanel.LabelForeColor
};
_checkBox.CheckedChanged += new EventHandler(OnCheckBoxCheckedChanged);

_checkBox.CheckedChanged += OnCheckBoxCheckedChanged;

AddedControls.Add(_checkBox);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ private EditorPropertyLine(IServiceProvider serviceProvider, DesignerActionPanel
: base(serviceProvider, actionPanel)
{
_button = new EditorButton();
_button.Click += new EventHandler(OnButtonClick);
_button.GotFocus += new EventHandler(OnButtonGotFocus);
_button.Click += OnButtonClick;
_button.GotFocus += OnButtonGotFocus;

AddedControls.Add(_button);
}
Expand All @@ -54,8 +54,9 @@ private unsafe void ActivateDropDown()
IntegralHeight = false,
Font = ActionPanel.Font
};
listBox.SelectedIndexChanged += new EventHandler(OnListBoxSelectedIndexChanged);
listBox.KeyDown += new KeyEventHandler(OnListBoxKeyDown);

listBox.SelectedIndexChanged += OnListBoxSelectedIndexChanged;
listBox.KeyDown += OnListBoxKeyDown;

TypeConverter.StandardValuesCollection? standardValues = GetStandardValues();
if (standardValues is not null)
Expand Down Expand Up @@ -112,8 +113,8 @@ private unsafe void ActivateDropDown()
}
finally
{
listBox.SelectedIndexChanged -= new EventHandler(OnListBoxSelectedIndexChanged);
listBox.KeyDown -= new KeyEventHandler(OnListBoxKeyDown);
listBox.SelectedIndexChanged -= OnListBoxSelectedIndexChanged;
listBox.KeyDown -= OnListBoxKeyDown;
}

if (!_ignoreDropDownValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ private MethodLine(IServiceProvider serviceProvider, DesignerActionPanel actionP
UseMnemonic = false,
VisitedLinkColor = ActionPanel.LinkColor
};
_linkLabel.LinkClicked += new LinkLabelLinkClickedEventHandler(OnLinkLabelLinkClicked);

_linkLabel.LinkClicked += OnLinkLabelLinkClicked;
AddedControls.Add(_linkLabel);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ private sealed class PanelHeaderLine : Line
private PanelHeaderLine(IServiceProvider serviceProvider, DesignerActionPanel actionPanel)
: base(serviceProvider, actionPanel)
{
actionPanel.FontChanged += new EventHandler(OnParentControlFontChanged);
actionPanel.FontChanged += OnParentControlFontChanged;

_titleLabel = new Label
{
Expand All @@ -40,8 +40,8 @@ private PanelHeaderLine(IServiceProvider serviceProvider, DesignerActionPanel ac
AddedControls.Add(_subtitleLabel);

// TODO: Need to figure out how to unhook these events. Perhaps have Initialize() and Cleanup() methods.
ActionPanel.FormActivated += new EventHandler(OnFormActivated);
ActionPanel.FormDeactivate += new EventHandler(OnFormDeactivate);
ActionPanel.FormActivated += OnFormActivated;
ActionPanel.FormDeactivate += OnFormDeactivate;
}

public override string FocusId => string.Empty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,22 @@ protected TextBoxPropertyLine(IServiceProvider serviceProvider, DesignerActionPa
UseMnemonic = false,
Visible = false
};
_readOnlyTextBoxLabel.MouseClick += new MouseEventHandler(OnReadOnlyTextBoxLabelClick);
_readOnlyTextBoxLabel.Enter += new EventHandler(OnReadOnlyTextBoxLabelEnter);
_readOnlyTextBoxLabel.Leave += new EventHandler(OnReadOnlyTextBoxLabelLeave);
_readOnlyTextBoxLabel.KeyDown += new KeyEventHandler(OnReadOnlyTextBoxLabelKeyDown);

_readOnlyTextBoxLabel.MouseClick += OnReadOnlyTextBoxLabelClick;
_readOnlyTextBoxLabel.Enter += OnReadOnlyTextBoxLabelEnter;
_readOnlyTextBoxLabel.Leave += OnReadOnlyTextBoxLabelLeave;
_readOnlyTextBoxLabel.KeyDown += OnReadOnlyTextBoxLabelKeyDown;

_textBox = new TextBox
{
BorderStyle = BorderStyle.None,
TextAlign = HorizontalAlignment.Left,
Visible = false
};
_textBox.TextChanged += new EventHandler(OnTextBoxTextChanged);
_textBox.KeyDown += new KeyEventHandler(OnTextBoxKeyDown);
_textBox.LostFocus += new EventHandler(OnTextBoxLostFocus);

_textBox.TextChanged += OnTextBoxTextChanged;
_textBox.KeyDown += OnTextBoxKeyDown;
_textBox.LostFocus += OnTextBoxLostFocus;

AddedControls.Add(_readOnlyTextBoxLabel);
AddedControls.Add(_textBox);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ private class TextLine : Line
protected TextLine(IServiceProvider serviceProvider, DesignerActionPanel actionPanel)
: base(serviceProvider, actionPanel)
{
actionPanel.FontChanged += new EventHandler(OnParentControlFontChanged);
actionPanel.FontChanged += OnParentControlFontChanged;
_label = new Label
{
BackColor = Color.Transparent,
ForeColor = ActionPanel.LabelForeColor,
TextAlign = ContentAlignment.MiddleLeft,
UseMnemonic = false,
};

AddedControls.Add(_label);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ private void OnFormClosing(object? sender, CancelEventArgs e)
Form form = (Form)TopLevelControl;
if (form is not null)
{
form.Closing -= new CancelEventHandler(OnFormClosing);
form.Closing -= OnFormClosing;
}
}
}
Expand All @@ -440,7 +440,7 @@ protected override void OnHandleCreated(EventArgs e)
base.OnHandleCreated(e);
if (TopLevelControl is Form form)
{
form.Closing += new CancelEventHandler(OnFormClosing);
form.Closing += OnFormClosing;
}
}

Expand Down Expand Up @@ -480,6 +480,7 @@ protected override void OnPaint(PaintEventArgs e)
}

Rectangle originalClip = e.ClipRectangle;

// Determine the first line index to paint
int index = 0;
while ((index < (_lineYPositions.Count - 1)) && (_lineYPositions[index + 1] <= originalClip.Top))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public DesignerActionService(IServiceProvider? serviceProvider)

if (serviceProvider.TryGetService(out IComponentChangeService? componentChangeService))
{
componentChangeService.ComponentRemoved += new ComponentEventHandler(OnComponentRemoved);
componentChangeService.ComponentRemoved += OnComponentRemoved;
}

_selectionService = serviceProvider.GetService<ISelectionService>();
Expand Down Expand Up @@ -128,7 +128,7 @@ protected virtual void Dispose(bool disposing)

if (_serviceProvider.TryGetService(out IComponentChangeService? componentChangeService))
{
componentChangeService.ComponentRemoved -= new ComponentEventHandler(OnComponentRemoved);
componentChangeService.ComponentRemoved -= OnComponentRemoved;
}
}
}
Expand Down Expand Up @@ -192,7 +192,7 @@ protected virtual void GetComponentDesignerActions(IComponent component, Designe

if (hookupEvents)
{
verb.CommandChanged += new EventHandler(OnVerbStatusChanged);
verb.CommandChanged += OnVerbStatusChanged;
}

if (verb is { Enabled: true, Visible: true })
Expand Down
Loading
0