QuestionCheckbox Errors

Posts 14 of 4 · Page 1 of 1
Checkbox Errors
No matter what combination I try to use I continue to get this same error

Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Web;

namespace Page_75_Exercise
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (checkBox1.Checked == true)
            {

                if (label1.BackColor == Color.Red)
                {

                    label1.BackColor = Color.Blue;
                }

                else
                {
                    label1.BackColor = Color.Red;
                }

            }
            else
            {
                MessageBox.Show("The Checkbox is not selected!");
            }
        }
    }
}
My error
When you double-click on a control in the GUI editor, 2 things happen

1) It takes you to the code. If it doesn't exist yet, it will create the default (Click for buttons, CheckChanged for this, etc etc) event code.
2) It hooks up the event handler is the "background form partial class".

You erased the function "checkBox1_CheckedChanged", but VS wasn't smart enough to detect that and still tries to hook up the checkbox's event to a function that doesn't exists anymore. ?

Just erase the line hooking up the event.


In the Form1 code, right click on "InitializeComponent" and select "Go to Definition", it will take you to Form1.Designer.Cs, the other "partial class" for the form1, where the controls code is kept. Inside that function is where the event handler normally gets hooked up. In your screenshot, the line with the error. * Erase it, you don't actually care about that event.
Quote Originally Posted by abuckau907 View Post
When you double-click on a control in the GUI editor, 2 things happen

1) It takes you to the code. If it doesn't exist yet, it will create the default (Click for buttons, CheckChanged for this, etc etc) event code.
2) It hooks up the event handler is the "background form partial class".

You erased the function "checkBox1_CheckedChanged", but VS wasn't smart enough to detect that and still tries to hook up the checkbox's event to a function that doesn't exists anymore. ?

Just erase the line hooking up the event.


In the Form1 code, right click on "InitializeComponent" and select "Go to Definition", it will take you to Form1.Designer.Cs, the other "partial class" for the form1, where the controls code is kept. Inside that function is where the event handler normally gets hooked up. In your screenshot, the line with the error. * Erase it, you don't actually care about that event.
Suprised I didn't try that lol, thanks for the help it worked.
Haha, it's probably better than you don't just erase lines with errors in them : p


Sometimes the IDE is nice for doing things in the background, sometimes not nice. In VB it would have auto-erased the event hookup if you erased the function ; D Thanks for the Thanks, see ya.
Posts 14 of 4 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?