将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
在所有情况下,从
BackColor
,DateTimePicker
和TextBox1
读回的TextBox2
具有相同的ARGB值但是,当单击
Button2
时,屏幕上TextBox1
的BackColor
实际上是F0F0F0(来自屏幕抓取颜色选择器)-是否对此有解释?我认为这也适用于C#,因此也适用于标记。
最佳答案
您可以使用ReadOnly
属性而不是Enabled
属性来控制可编辑行为并分配自定义BackColor
。