KritoTR form bu şekilde
private void TextBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
//enter' a basıldığında buraya girer.
listBox1.Items.Insert(5,textBox1.Text);
}
}
private void Button1_Click(object sender, EventArgs e)
{
switch(islem)
{
case 1:
B();
break;
case 2:
C();
break;
case 3:
D();
break;
case 4:
E();
break;
case 5:
F();
break;
case 6:
G();
break;
case 7:
H();
break;
case 8:
ekle();
break;
}
}
int islem;
private void RadioButton1_CheckedChanged(object sender, EventArgs e)
{
islem = 1;
}
private void RadioButton2_CheckedChanged(object sender, EventArgs e)
{
islem = 2;
}
private void RadioButton3_CheckedChanged(object sender, EventArgs e)
{
islem = 3;
}
private void RadioButton4_CheckedChanged(object sender, EventArgs e)
{
islem = 4;
}
private void RadioButton5_CheckedChanged(object sender, EventArgs e)
{
islem = 5;
}
private void RadioButton6_CheckedChanged(object sender, EventArgs e)
{
islem = 6;
}
private void RadioButton7_CheckedChanged(object sender, EventArgs e)
{
islem = 7;
}
private void RadioButton8_CheckedChanged(object sender, EventArgs e)
{
islem = 8;
}
public void B()
{
int say = 0;
foreach (var item in listBox1.Items)
{
if (textBox1.Text == item.ToString())
{
say++;
}
}
MessageBox.Show("Texbox daki elemandan ListBox da şu kadar vardır = " + say);
}
public void C()
{
int a = listBox1.Items.Count;
if (a >= 5)
{
for (int i = 1; i < 6; i++)
{
listBox1.Items.RemoveAt( a- i);
}
}
}
public void D()
{
listBox1.SelectionMode = SelectionMode.MultiSimple;
for (int i = 0; i < listBox1.Items.Count; i++)
{
listBox1.SelectedIndex = i;
}
}
public void E()
{
//ArrayList için 'using System.Collections;' eklenmeli
ArrayList list = new ArrayList();
foreach (object o in listBox1.Items)
{
list.Add(o);
}
list.Sort();
list.Reverse();
listBox1.Items.Clear();
foreach (object o in list)
{
listBox1.Items.Add(o);
}
}
public void F()
{
int say = 0;
foreach (var item in listBox1.Items)
{
if ("Er" == item.ToString().Substring(0,2))
{
say++;
}
}
MessageBox.Show("Er ile başlayan " + say + " kadar eleman vardır");
}
public void G()
{
foreach (var item in listBox1.Items)
{
MessageBox.Show(item.ToString());
}
}
public void H()
{
MessageBox.Show(listBox1.SelectedIndices.Count.ToString());
}
public void ekle()
{
listBox1.Items.Add(textBox1.Text);
listBox1.Refresh();
}