So I'm a beginner with C#, in the middle of my course at Tafe, and I've been trying to make a Checklist in Visual Studio when I've had some free time at the end of my lesson. I managed to figure out how to make checkboxes appear on a button click from a website, and due to some tinkering I figured out how to make them appear where I wanted them to be, but there are some things I haven't found out how to do yet that I could use a little help with.
Inside the button click event, from memory, this is what I have:
//For a variable I made outside the button, set to 0 on startup
box = new CheckBox();
//with a text box on the form
box.Text = txtAddItem.Text;
box.Location = new Point(10, (65 + (intValue * 10)));
Now I may have other bits of essential code in the event creating the checkbox, but this is all I remember. I don't have access to Visual Studio right now. What I'm having problems with is that every time a new instance of box is created, the old one no longer recognises that value so when I have something like this under a new button click event:
bool blnCheck = box.Checked;
//I may have been using a different command here than dispose. Originally I used hide, but it worked just about as well as the other ones.
So basically, the problem I've been getting is that when that last button's clicked, only the most recently placed checkbox gets removed. I recently (like, just now) figured out the other problem I'd been having with it, being the intValue not removing a value when I've been clicking the button. So, if I could have some help with this, it'd be much appreciated.
tl;dr: Only the last checkbox I'm placing is being deleted, refer to code for details.
by Gate4043 via /r/csharp