Listbox ta seçilen değere sahip Textbox ın rengini değiştir — Csharp

Listbox ta seçilen değere sahip Textbox ın rengini değiştir — Csharp

Soru :  Form açıldığında  15 adet textbox ın içine rastgele sayı gelecektir. Listboxta tıklanan değer ile aynı olan textbox ın arka plan rengi değişecektir.

 

textbox_renk_degistir3

 

[code lang=”csharp”]

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;//www.gorselprogramlama.com
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace random_textbox_sayi_ekle
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private TextBox[] txtSoru;//www.gorselprogramlama.com
private void Form1_Load(object sender, EventArgs e)
{
for (int i = 0; i < 15; i++)
{
listBox1.Items.Add(i);
}

txtSoru = new TextBox[15];//www.gorselprogramlama.com

for (int i = 0; i < 15; i++)
{

txtSoru[i] = new TextBox();

txtSoru[i].Location = new Point(50, 26 * i+10);

this.Controls.Add(txtSoru[i]);//www.gorselprogramlama.com

}
Random r = new Random();
for (int i = 0; i < 15; i++)
{
txtSoru[i].Text = r.Next(16).ToString();
}
}

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
for (int i = 0; i < 15; i++)
{
txtSoru[i].BackColor = System.Drawing.SystemColors.Window;
}
for (int i = 0; i < 15; i++) //www.gorselprogramlama.com
{
if(Convert.ToInt32( listBox1.Text)== Convert.ToInt32(txtSoru[i].Text))
{
txtSoru[i].BackColor = Color.Red;
}
}

}
}
}

[/code]

 

textbox_renk_degistir

 

textbox_renk_degistir2

Projeyi İNDİR

Bir yanıt yazın

E-posta adresiniz yayınlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir