CheckBox event



  • In a separate class CheckBox and in shape.

    Here's the class:

    class CheckBoxCreate
    {
        CheckBox[] check;
        private Form cont;
    
    public CheckBoxCreate( Form cont )
    {
        this.cont = cont;
    }
    
    public void CreateCheck()
    {
        DirectoryInfo dir = new DirectoryInfo( @"12" );
        FileInfo[] inf = dir.GetFiles( "*.txt" );
        check = new CheckBox[inf.Length];
    
        for ( int i = 0; i < inf.Length; i++ )
        {
            check[i] = new CheckBox();
            check[i].Visible = true;
            check[i].Parent = cont;
            check[i].Location = new Point( 200, 5 + i * 50 );
            check[i].Name = i.ToString();
            check[i].Text = "Чекбокс номер " + i;
            check[i].Checked = true;
            check[i].Width = 120;
            check[i].Height = 40;
            check[i].CheckedChanged += new EventHandler(check_Change);
            cont.Controls.Add( check[i] );
        }
    }
    
    public void check_Change( object sender, EventArgs e )
    {
    
    }
    

    }

    It's working well, and it's getting right out.
    There's a button on the uniform, when it's clicked, it has to cause an event. check_Change of
    to remove all flags from the CheckBox
    How do you want to do where to dig?
    It's just a sketch to connect and write a program.



  • Removing the checkbox is a reason to call the event. check_Change) is an investigation. The reverse is wrong. i.e. manual challenge check_Change There's nothing to do with the chequebox condition.

    The chequebox condition can be replaced by the checked properties. Ask him for all chequeboxes in shape, it's like:

    private void button1_Click(object sender, EventArgs e)
    {
        foreach (var checkbox in this.Controls.OfType<CheckBox>())
        {
            checkbox.Checked = true;
        }
    }
    

    In your case, you're already tracking the chequeboxes that have been created, so it's enough to remember the reference to the checkBoxCreate used in the field of uniform, and in the button processor, use it to cross the chequeboxes:

    Class of shape field:

    СheckBoxCreate checkBoxCreate;
    

    chequebox code:

    this.checkBoxCreate = new CheckBoxCreate(this);
    this.checkBoxCreate.CreateCheck();
    

    on the button:

    private void button1_Click(object sender, EventArgs e)
    {
        this.checkBoxCreate.CheckAll();
    }
    

    where

    class CheckBoxCreate
    {
        ...
        public void CheckAll()
        {
            foreach (var checkbox in this.check)
            {
                checkbox.Checked = true;
            }
        }
    }
    

Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2