Another Home work problem, but have been at it a bit so thought I would throw something up.
I have defined a custom control that has an event that is called BoolChanged that should be triggered when the bool DecimalPointAllowed is changed to false by a check box. When the event is triggered a label shoud let us know that that the "Decimal point is allowed"
The checked check box is changing the DecimalPointAlowed to false, but the even is not being triggered and the label is not changing.
This is the custom control with the event.
Code:
public class DoubleValueEdit : TextBox
{
internal delegate void MyBoolValueChanged(bool Was, string result);
internal event MyBoolValueChanged BoolChanged;
public bool DecimalPointAllowed;
string a = "a";
public double Value
{
get
{
double Val;
if (double.TryParse(Text, out Val))
return Val;
else
return 0;
}
set
{
Text = value.ToString();
if ((DecimalPointAllowed = true) && (BoolChanged != null))
BoolChanged(DecimalPointAllowed, a);
}
}
Here is the Check box code and label that should change upon checking the checkbox. By calling the event based on the bool value changing.
Code:
public partial class Form1 : Form
{
string result2;
public Form1()
{
InitializeComponent();
}
private void doubleValueEdit1_TextChanged(object sender, EventArgs e)
{
dvLabel.Text = doubleValueEdit1.Value.ToString();
doubleValueEdit1.BoolChanged += new DoubleValueEdit.MyBoolValueChanged(doubleValueEdit1_BoolChanged);
}
void doubleValueEdit1_BoolChanged(bool Was, string result)
{
result2 = Was.ToString() + result + "Decimal Point Allowed";
}
private void ChBoolValCheckBox_CheckedChanged(object sender, EventArgs e)
{
if (ChBoolValCheckBox.Checked)
doubleValueEdit1.DecimalPointAllowed = false;
}