Telling you before hand, i am just starting to learn, so please refrain from making fun of me i k i am real weak in this.

ok here is what i need to do, i have been trying for ages but i am having huge problem creating dynamic checkboxes. This is what needs to be done.
When user clicks in the textbox, “Write a Quick Note” text should go away.

  1. When user writes something and presses ENTER key, it should add the text user just
    entered in the checklist below that textbox. For example I write “Prayer” and press enter,
    it gets added in the checklist.
  2. Window must NOT be resizable. That is, user shouldn’t be able to change the size of this
    form. It must be fixed!
  3. Once user “check” some item in the TODO list, it should be deleted from the list. For
    example, in the above list, no item is selected. Now I select “Rest” from the above shown
    list – it should be deleted from the list at once.
  4. If I close down the program and starts it again, it should load the previously added
    checklist items automatically, i.e. data should be persistent!

I have done the 4th and 5th(somewhat)... i cant get my head around point 4. Ik 6th point has summin to do with event handling. i'll show you what i have done so far:

    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.IO;

    namespace Lab10
    {
        public partial class Form1 : Form
        {

            public Form1()
            {
                InitializeComponent();
            }

            private void textBox1_Click(object sender, EventArgs e)
            {
                textBox1.Clear();
            }

            private void checkBox1_CheckStateChanged(object sender, EventArgs e)
            {
                checkBox1.Hide();
            }

            private void textBox1_Enter(object sender, EventArgs e)
            {

                //The data i enter in the textbox should become a checkbox when i hit enter. so this is what i tried.
                /*CheckBox dynam = new CheckBox();
                    dynam.Name = dynam.ToString();
                    dynam.Text = dynam.ToString();
                    richTextBox1.Controls.Add(dynam);*/


                }

            }
        }
    }

Thank you for any help!

Create a panel that will contain your checkboxes.

When you add a checkbox, add it to the panel's control list. Make sure you set the correct form co-ordinates (they are relative to the parent so (0,0) would be the top left of the panel)

The name of your checkbox can be whatever you list, the text should be set to the value you entered into textBox1.Text.

When you create the checkbox, you will need to assign the "CheckStateChanged" event manually. Hitting "Tab" to do the Visual Studio autocomplete will accomplish most of this for you.

If you want more detailed instructions, use the search at the top of the page. I explained this (with code examples) a little less than a week ago :)

To set a form non resizable,
set the MaximizeBox property to false
set the FormBorderStyle property to FixedDialog

@ddanbe.. thank you i have already done that :)

ok this is what i have done so far... and its working well.. now i only need to delete the checkboxes when i click on them.. their state needs to be changed first..

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.IO;

namespace Lab10
{
    public partial class Form1 : Form
    {
        public string all;
        public Form1()
        {
            InitializeComponent();
        }

        private void textBox1_Click(object sender, EventArgs e)
        {
            textBox1.Clear();
        }

        private void textBox1_KeyPress_1(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)Keys.Enter)
            {

                all += textBox1.Text + Environment.NewLine;
                checkedListBox1.Items.Add(textBox1.Text);
                textBox1.Text = "";
            }

            try
            {
                StreamWriter sw = new StreamWriter(@"D:\Mcc02123059.txt"); //Entered data saves in D Partition.
                sw.WriteLine(all); //Prints the data being entered in the textbox
                sw.Close();
            }
            catch
            {
            }
        }

        private void checkedListBox1_Click(object sender, EventArgs e)
        {
            checkedListBox1.Items.Remove(OnClick); //not working
        }

        }
    }

all kind of help is highly appreciated :)

well thank you all for your help i have figured it out! i did this...

private void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e)
        {
            checkedListBox1.Items.Remove(checkedListBox1.SelectedItem);
        }

sorry guys but i have another problem.. its all working BUT... i get this error when i try to click on the checkbox..

"Object reference not set to an instance of an object."

Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    Application.Run(new Form1()

help me guys.. quick!

Add a ); to line 3 of your code

@ddane.. yes it is there.. i forgot to paste that part

The error message says, that somewhere in your code you forgot to use the keyword new. Can you show the line wher the error occurred?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.