将DateTimePicker,两个文本框和两个按钮添加到窗体

添加以下代码:


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


在所有情况下,从BackColorDateTimePickerTextBox1读回的TextBox2具有相同的ARGB值

但是,当单击Button2时,屏幕上TextBox1BackColor实际上是F0F0F0(来自屏幕抓取颜色选择器)-是否对此有解释?

我认为这也适用于C#,因此也适用于标记。

最佳答案

您可以使用ReadOnly属性而不是Enabled属性来控制可编辑行为并分配自定义BackColor

10-08 14:49