Thank you nukefusion. The Compact Framework (I'm developing for Windows Mobile) doesn't have the CheckedChanged event. It's called CheckStateChanged. Why they change the names of things, I don't know. It looks like it does nothing other than making porting over difficult.
This is how the code looks now, and it works as it should:
- public void Add_CheckBox(String CBText)
-
{
-
CheckBox MyCheckbox = new CheckBox();
-
MyCheckbox.Location = new System.Drawing.Point(4, CB_Row * 20);
-
MyCheckbox.Name = "MycheckBox" + CB_Row;
-
MyCheckbox.Text = CBText;
-
MyCheckbox.Font = NormalFont;
-
MyCheckbox.Size = new System.Drawing.Size(CBText.Length * 12, 20);
-
MyCheckbox.TabIndex = CB_Row;
-
MyCheckbox.CheckStateChanged += new EventHandler(MyCheckbox_CheckStateChanged);
-
this.Controls.Add(MyCheckbox);
-
CB_Row = CB_Row + 1;
-
}
-
-
private void MyCheckbox_CheckStateChanged(object sender, EventArgs e)
-
{
-
CheckBox MyCheckbox = (CheckBox)sender;
-
if (MyCheckbox.Checked)
-
{
-
MyCheckbox.ForeColor = Color.Gray;
-
MyCheckbox.Font = StrikeoutFont;
-
}
-
else
-
{
-
MyCheckbox.ForeColor = Color.Black;
-
MyCheckbox.Font = NormalFont;
-
}
-
}
-
I think my main problem these past couple of days trying to get this to work is I wasn't issuing 'CheckBox MyCheckbox = (CheckBox)sender;' to get the CheckBox object I needed. Like I said before, I'm still rather new to OO programing. All this overloading and inheritance stuff is a bit confusing to an old school C programmer at first.
I really appreciate your help and the existence of bytes. You'll most likely see me here again until I get this OO stuff down.