c# ta bir groupBox um var. içinde A dan Z ye kadar harflerin bulunduğu CheckBox larım var toplam 30 tane. istediğim hangi CheckBox seçiliyse kırmızı olsun hangisi seçili değilse siyah yada normal renginde olsun.
formun load ına aşağıdaki gibi foreach oluşturdum fakat başarılı olmadı, herhangi bir hata almıyorum. hata nerdedir yardımcı olabilecek varsa sevinirim.
form loada değil checkbox clicke koy yazdığını örnek program
using System; using System.Collections.Generic; using System.Drawing; using System.Windows.Forms;
namespace bnmg {
public partial class MainForm : Form { public MainForm() {
InitializeComponent();
}
public CheckBox[] check=new CheckBox[8]; void MainFormLoad(object sender, EventArgs e) { for (int i = 0; i < check.Length; i++) {
check[i] = new CheckBox(); check[i].Left = 5; check[i].Width=50; check[i].Top = i*30+20; check[i].Click+= new System.EventHandler(tıkla); check[i].Text=i.ToString(); groupBox1. Controls.Add(check[i]); }
} public void tıkla(Object sender, System.EventArgs e) { foreach (Control c in groupBox1.Controls) { if (c is CheckBox) { if (((CheckBox)c).Checked == true) { ((CheckBox)c).ForeColor = Color.Red;
c# ta bir groupBox um var. içinde A dan Z ye kadar harflerin bulunduğu CheckBox larım var toplam 30 tane.
istediğim hangi CheckBox seçiliyse kırmızı olsun hangisi seçili değilse siyah yada normal renginde olsun.
formun load ına aşağıdaki gibi foreach oluşturdum fakat başarılı olmadı, herhangi bir hata almıyorum.
hata nerdedir yardımcı olabilecek varsa sevinirim.
istediğim durum: < Resime gitmek için tıklayın >
foreach (Control c in groupBox8.Controls)
{
if (c is CheckBox)
{
if (((CheckBox)c).Checked == true)
{
((CheckBox)c).ForeColor = Color.Red;
}
else
{
((CheckBox)c).ForeColor = Color.Black;
}
}
};
< Bu mesaj bu kişi tarafından değiştirildi reyta -- 21 Nisan 2015; 15:24:09 >