How to set backcolor for all textboxes in winform globally?
how to set backcolor for all textboxes in winform globally c#?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Michal HabalcikRank #902 · 2.3K reputationPosted Nov 25, 2014, 8:11 PM EST
foreach (var control in this.Controls)
{
var box = control as TextBox;
if (box != null)
box.BackColor = Color.Red;
}Prathap39 reputationPosted Nov 25, 2014, 8:26 PM EST
Munesh SharmaRank #174 · 13.9K reputationPosted Nov 25, 2014, 8:43 PM EST
public void colorchange()
{
Action<Control.ControlCollection> coll= null;
foreach (Control c in coll)
{
if (c is TextBox )
(control as TextBox).BackColor = Color.blue;
}
}
}
Joginder BangerRank #360 · 7K reputationPosted Nov 25, 2014, 8:48 PM EST
add a new class in your code,call this class every pages.
public class mycolor
{
public mycolor(coltrol ctr)
{
foreach (var control in ctr)
{
var box = control as TextBox;
if (box != null)
box.BackColor = Color.Red;
}}
}
Prathap39 reputationPosted Nov 25, 2014, 8:58 PM EST
Joginder BangerRank #360 · 7K reputationPosted Nov 25, 2014, 9:07 PM EST
{
public mycolor(coltrol ctr)
{
foreach (var control in ctr)
{
var box = control as TextBox;
if(box.text!=null && box.text!="")
{
box.BackColor = Color.Red;
}
}}
}