在form1构造函数中,我将textBox forecolor设置为绿色:
cTextBox3.WaterMarkForeColor = Color.Green;
cTextBox3.WaterMarkActiveForeColor = Color.Green;
cTextBox3.ForeColor = Color.Green;
cTextBox3.WaterMark = "Browse To The File Location";
然后我有一个带有openFileDialog的按钮点击事件
private void button6_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "c:\\";
openFileDialog1.Filter = "Json Files (*.json)|*.json";
openFileDialog1.FilterIndex = 0;
openFileDialog1.RestoreDirectory = true;
openFileDialog1.Multiselect = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
cTextBox3.Text = openFileDialog1.FileName;
w = new StreamWriter(AuthenticationFileName, true);
w.WriteLine(cTextBox3.Text);
w.Close();
}
}
在设计器中,我将cTextBox3 ReadOnly属性设置为true。
问题是,一旦将openFileDialog1.FileName的文本分配给cTextBox3.Text文本为黑色。我希望它是绿色的。 我尝试在行之前添加:
cTextBox3.Text = openFileDialog1.FileName;
所有颜色都像我在构造函数中所做的那样变为绿色我尝试将cTextBox3 ReadOnly属性设置为false再次设置颜色然后再次将其设置为true并且文本仍为黑色。
答案 0 :(得分:3)
这是由于视觉风格。除非你想完全禁用它们,否则你还需要设置背景颜色,例如:
tbx.ReadOnly = true;
tbx.BackColor = Color.White;
tbx.ForeColor = Color.Green;