Skip to content
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

VB -> C#: Multi-line WinForms 'Handles' syntax silently drops events #701

Closed
jconnop opened this issue Feb 4, 2021 · 0 comments
Closed
Labels
VB -> C# Specific to VB -> C# conversion

Comments

@jconnop
Copy link
Contributor

jconnop commented Feb 4, 2021

Input code

In Form1.vb :

Public Class Form1
    Private Sub MultiClickHandler(sender As Object, e As EventArgs) Handles Button1.Click,
                                                                            Button2.Click
        MessageBox.Show($"Handled event from {DirectCast(sender, Control).Name}")
    End Sub
End Class

Erroneous output

In Form1.Designer.cs :

        private void InitializeComponent()
        {
            _Button1 = new Button();
            _Button1.Click += new EventHandler(MultiClickHandler);
            Button2 = new Button();
            SuspendLayout();

Expected output

In Form1.Designer.cs :

        private void InitializeComponent()
        {
            _Button1 = new Button();
            _Button1.Click += new EventHandler(MultiClickHandler);
            _Button2 = new Button();
            _Button2.Click += new EventHandler(MultiClickHandler);
            SuspendLayout();

Alternative Working Input

The conversion works fine if the input events are all on one line, i.e. :

Public Class Form1
    Private Sub MultiClickHandler(sender As Object, e As EventArgs) Handles Button1.Click, Button2.Click
        MessageBox.Show($"Handled event from {DirectCast(sender, Control).Name}")
    End Sub
End Class

Details

  • Product in use: VS extension
  • Version in use: 8.2.2
  • Did you see it working in a previous version, which? No
  • This is particularly problematic as the conversion produces no error, and the output compiles, but the behaviour of the program changes.
@jconnop jconnop added the VB -> C# Specific to VB -> C# conversion label Feb 4, 2021
GrahamTheCoder added a commit that referenced this issue Feb 7, 2021
Trim whitespace from event source identifiers. Fixes #701
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
VB -> C# Specific to VB -> C# conversion
Projects
None yet
Development

No branches or pull requests

1 participant