Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 797739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T22:51:24+00:00 2026-05-14T22:51:24+00:00

I’m new to the Visual C# designer so these are general and pretty basic

  • 0

I’m new to the Visual C# designer so these are general and pretty basic question on how to work with the designer.

When we for instance add a label to a form and then double-click on it in the Visual C# designer (I’m using Microsoft Visual C# 2008 Express Edition), the following things happen:

  1. The designer generates code within Form1.Designer.cs (assume default names for simplicity) to add the label,
  2. then with the double-click it will add the event handler label1_Click to the label within Form1.Designer.cs, using the following code

    this.label1.Click += new System.EventHandler(this.label1_Click);

and it adds the event handler method to Form1.cs

private void label1_Click(object sender, EventArgs e)
{

}

If I now remove the label only the code within Form1.Designer.cs will be removed but the label1_Click method will stay within Form1.cs even if it isn’t used by anything else. But if I’m using reset within Properties->Events for the Click-event from within the designer even the label1_Click method in Form1.cs will be removed.

1.) Isn’t that a little inconsistent behavior?

2.) What is the recommended way of removing such generated event handler-code?

3.) What is the best “mental approach”/best practice for using the designer?

I would approach it by mental separation in the way that Form1.cs is 100% my responsibility and that on the other hand I’m not touching the code in Form1.Designer.cs at all. Does that make sense or not? Since sometimes the designer removes sth. from Form1.cs I’m not sure about this.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T22:51:25+00:00Added an answer on May 14, 2026 at 10:51 pm

    1) Yes, it is inconsistent. A little.
    2) I used MUCH MORE SIMPLE approach: simple wipe out all your handle code and try to compile => compiler will show you where to wipe out an event assignment. Despite of scary look, it is really safe.
    3) Here is my best practices which I recommend and kind of enforce in my software department:
    3a) Switch to WPF (ask for best WPF practices separately; there are a lot of other problems);
    3b) NEVER ever allow Visual Studio to auto-generate event code (WPF or Windows.Forms); in case of accident use (2) as soon as possible;
    3b) For event assignment use anonymous lambda:

    ByButton.Click += (source, evArg) => { SomeHandler(...); };
    

    for v.2.0:

    ByButton.Click += delegate(object source, EventArgs evArgs) { SomeHandler(...); };
    

    There are many benefits: your handlers are not bound to using specific method profile; you can put whole code inside anonymous handler is it is short enough, in lambda form you may never need to know the type of Event Arguments…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 394k
  • Answers 394k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It is possible to share resources with Maven, for example… May 15, 2026 at 2:14 am
  • Editorial Team
    Editorial Team added an answer It seems to be the outline of the coordinates area,… May 15, 2026 at 2:14 am
  • Editorial Team
    Editorial Team added an answer The activemq.prefetchSize is only available on a SUBSCRIBE message, not… May 15, 2026 at 2:14 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.