Add a DateTimePicker, two TextBoxes and two Buttons to a Form
Add the following code:
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
DateTimePicker1.Enabled = True
TextBox1.Enabled = True
TextBox2.Enabled = True
TextBox1.BackColor = DateTimePicker1.BackColor
TextBox2.BackColor = Color.FromArgb(DateTimePicker1.BackColor.A, DateTimePicker1.BackColor.R, DateTimePicker1.BackColor.G, DateTimePicker1.BackColor.B)
End Sub
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
DateTimePicker1.Enabled = False
TextBox1.Enabled = False
TextBox2.Enabled = False
TextBox1.BackColor = DateTimePicker1.BackColor
TextBox2.BackColor = Color.FromArgb(DateTimePicker1.BackColor.A, DateTimePicker1.BackColor.R, DateTimePicker1.BackColor.G, DateTimePicker1.BackColor.B)
End Sub
In all cases the BackColor read back from the DateTimePicker, TextBox1 and TextBox2 has the same ARGB values
But when Button2 is clicked, TextBox1‘s BackColor on screen is actually F0F0F0 (from screen grab colour picker)- Is there an explanation for this?
I assume this applies to C# as well – hence the tag.
You could use the
ReadOnlyproperty instead ofEnabledproperty to control editable behavior and assign customBackColor.