none
Method must have a return type error RRS feed

  • Question

  • I have a simple page of code in c sharp (below). I get the error message "Method must have a return type" at the point indicated in the code. I cannot figure out why I'm getting this message, since the return type is clearly "void".

    If I delete that function, the squiggly line and error message just migrate to the code above it -- the LoginForm() function.

    Anybody help, please/

    using System;
    using System.Windows.Forms;

    namespace WFCS2
    {
        public partial class LoginForm : Form
        {
            public LoginForm()
            {
                InitializeComponent();
            }
            private void PasswordInstructionLabel_Click(object sender, EventArgs e)
            {

            }  //Here is where the squiggly line appears with the message "Method must have a return type"

            SubmitLoginButton_Click(object sender, EventArgs e)
            {
                if (LoginTextBox.Text == "")
                {
                    MessageBox.Show("Please Enter Password");
                }
                else if (LoginTextBox.Text == "seortgtp0")
                {
                    // Form2 x = new Form2();           //This is where you go when the login is successful
                    //  x.Show();
                }
                else
                {
                    MessageBox.Show("No good", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            private void LoginTextBox_TextChanged(object sender, EventArgs e)
            {

            }

          
        }
    }

    Tuesday, April 23, 2019 7:55 PM

Answers

  • Should look like this. zero issues here as I just created the form and code.

    namespace WFCS2
    {
        public partial class LoginForm : Form
        {
            public LoginForm()
            {
                InitializeComponent();
            }
            private void PasswordInstructionLabel_Click(object sender, EventArgs e)
            {
    
            } 
            private void SubmitLoginButton_Click(object sender, EventArgs e)
            {
                if (LoginTextBox.Text == "")
                {
                    MessageBox.Show("Please Enter Password");
                }
                else if (LoginTextBox.Text == "seortgtp0")
                {
                    // Form2 x = new Form2();           //This is where you go when the login is successful
                    //  x.Show();
                }
                else
                {
                    MessageBox.Show("No good", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            private void LoginTextBox_TextChanged(object sender, EventArgs e)
            {
    
            }
        }
    }
    


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Marked as answer by dammit_again Wednesday, April 24, 2019 12:43 AM
    Tuesday, April 23, 2019 8:48 PM
    Moderator

All replies

  • There is no return type to SubmitLoginButton_Click
    Tuesday, April 23, 2019 8:08 PM

  •         SubmitLoginButton_Click(object sender, EventArgs e)
            {

    As Castorix31 suggested, you need to specify the return type for button click
    event handlers:

    private void SubmitLoginButton_Click(object sender, EventArgs e
    

    - Wayne

    Tuesday, April 23, 2019 8:28 PM
  • Should look like this. zero issues here as I just created the form and code.

    namespace WFCS2
    {
        public partial class LoginForm : Form
        {
            public LoginForm()
            {
                InitializeComponent();
            }
            private void PasswordInstructionLabel_Click(object sender, EventArgs e)
            {
    
            } 
            private void SubmitLoginButton_Click(object sender, EventArgs e)
            {
                if (LoginTextBox.Text == "")
                {
                    MessageBox.Show("Please Enter Password");
                }
                else if (LoginTextBox.Text == "seortgtp0")
                {
                    // Form2 x = new Form2();           //This is where you go when the login is successful
                    //  x.Show();
                }
                else
                {
                    MessageBox.Show("No good", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            private void LoginTextBox_TextChanged(object sender, EventArgs e)
            {
    
            }
        }
    }
    


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Marked as answer by dammit_again Wednesday, April 24, 2019 12:43 AM
    Tuesday, April 23, 2019 8:48 PM
    Moderator
  • Thank you, guys - I guess I was looking in the wrong place.
    Wednesday, April 24, 2019 12:43 AM