CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2012
    Posts
    1

    Visual C# simple problem

    Hi,

    I'm fairly new to programming and I'm having a weird error in both the new Visual Studio Beta and Visual C# Express 2010.

    Here's the issue: I create a new Windows Form Application and add a button on it. I double click the button to get this code automatically:

    private void button1_Click(object sender, EventArgs e)
    {
    }

    However, if I decide to delete these three lines, my program won't compile anymore. I've messed around with with VB.net before and this didn't happen. Is it normal? How can I fix it?

    I realized that I can remove the code when I delete the button, but is there any other way? (If I double click on something by mistake for example.)

    Thanks a lot!


    Here's the error:

    Error 1 'WindowsFormsApplication1.Form1' does not contain a definition for 'button1_Click' and no extension method 'button1_Click' accepting a first argument of type 'WindowsFormsApplication1.Form1' could be found (are you missing a using directive or an assembly reference?) C:\Users\Username\AppData\Local\Temporary Projects\WindowsFormsApplication1\Form1.Designer.cs 42 64 WindowsFormsApplication1

  2. #2
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: Visual C# simple problem

    Quote Originally Posted by MightUndoIt View Post
    Hi,

    Error 1 'WindowsFormsApplication1.Form1' does not contain a definition for 'button1_Click' and no extension method 'button1_Click' accepting a first argument of type 'WindowsFormsApplication1.Form1' could be found (are you missing a using directive or an assembly reference?) C:\Users\Username\AppData\Local\Temporary Projects\WindowsFormsApplication1\Form1.Designer.cs 42 64 WindowsFormsApplication1
    This error is quite clear you unfortunatly created a click event by doing some clicks in the enviroment and when you delete the click events delegate you also need to delete the line where this delegate is used.
    Goto the Form1.Designer.cs
    How to do: rightclicking in Form1.cs the Forms
    InitializeComponent() method s and use 'goto definition' in the context menue then this will open the method which is located in the Dorm1.Designer.cs
    and in that method find the line
    Code:
      button1.Click += new System.EventHandler(this.button1_Click);
    
    and remove that line
    Then the error is gone
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

  3. #3
    Join Date
    Mar 2012
    Posts
    2

    Re: Visual C# simple problem

    Simple way, you double click on error line in Error list window, VS will help you find where a line make this error. In this situation, you can delete error line.

  4. #4
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: Visual C# simple problem

    Quote Originally Posted by zquanghoangz View Post
    Simple way, you double click on error line in Error list window, VS will help you find where a line make this error. In this situation, you can delete error line.
    Sorry if you only delete the errormessage and recompile you will still get the same erormessage you really need to go to the click event in the design view and there deleting the event delegate so this field of the click event is empty
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

  5. #5
    Join Date
    Mar 2012
    Posts
    2

    Re: Visual C# simple problem

    What I mean it really like you talk. Maybe I write too hard to understand.
    When you delete function, I will have error message, because delegate event already exist.
    So, double click on error you will go to error line. Delete that line. It's OK.

    I think it is normal error. Many newbie meet.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured