samedi 11 août 2018

Using Check Box State In Different Class

I have a checkbox that can be checked on my MainForm (windows form) and I want to check the value of the checkbox (checked or unchecked) in a different class. I have set the modifiers of the checkbox to public, and I am using .Checked to determine if the checkbox is checked, however it always evaluates to False

How should I alter my syntax so that the proper message is displayed based off the checkbox state?

partial class MainForm
{
    private void InitializeComponent()
    {
        this.checkBoxLine.AutoSize = true;
        this.checkBoxLine.Location = new System.Drawing.Point(3, 364);
        this.checkBoxLine.Name = "checkBoxLine";
        this.checkBoxLine.Size = new System.Drawing.Size(118, 17);
        this.checkBoxLine.TabIndex = 14;
        this.checkBoxLine.Text = "Line";
        this.checkBoxLine.UseVisualStyleBackColor = true;
        this.checkBoxLine.CheckedChanged += new System.EventHandler(this.checkBoxLine_CheckedChanged);
    }

public System.Windows.Forms.CheckBox checkBoxLine;
}

class DC1 : DC1
{
    MainForm mf = new MainForm();   

    public DC1()
    {
        CheckCheckboxStatus();
        InitializeComponent();
    }

    void CheckCheckboxStatus()
    {
        if (mf.checkBoxLine.Checked)
            MessageBox.Show("It Is Checked");
        else
            MessageBox.Show("It Is Not Checked");
    }
}




Aucun commentaire:

Enregistrer un commentaire