C#haylam
if (fontDialog1.ShowDialog() == DialogResult.OK)
textBox1.Font = fontDialog1.Font;
void ChuyenSinhVien(ListBox Chuyen, ListBox Nhan)
{
int i = 0;
string s;
while (i < Chuyen.Items.Count)
{
if (Chuyen.GetSelected(i) == true)
{
s = (string)Chuyen.Items[i];
Nhan.Items.Add((string)Chuyen.Items[i]);
Chuyen.Items.RemoveAt(i);
}
i++;
}
}
void ChuyenHetSinhVien(ListBox chuyen, ListBox nhan)
{
int i = 0;
string s;
while (i < chuyen.Items.Count)
{
s = (string)chuyen.Items[i];
nhan.Items.Add(s);
i++;
}
chuyen.Items.Clear();
}
void XoaSinhVien(ListBox LopAB)
{
int i = 0;
string s;
while (i < LopAB.Items.Count)
{
if (LopAB.GetSelected(i) == true)
{
s = (string)LopAB.Items[i];
LopAB.Items.RemoveAt(i);
}
i++;
}
}
private void Form1_Load(object sender, EventArgs e)
{
cmbchuyenlop.SelectedIndex = 0;
lst_LopA.Items.Add("abc");
lst_LopA.Items.Add("xyz");
lst_LopB.Items.Add("123");
lst_LopB.Items.Add("456");
lst_LopB.Items.Add("789");
}
int giatri()
{
int n;
Form2 frm = new Form2();
frm.ShowDialog();
n = int.Parse(frm.txtNhapGiaTri.Text);
return n;
}
int []a;
void taomang(int []a)
{
Random r = new Random();
for (int i = 0; i < a.Length; i++)
a[i]=r.Next(1,100);
}
void xuatmanggoc(int[] a)
{
foreach (int x in a)
rtbMangGoc.Text += x.ToString() + ' ';
}
void xuatmangkq(int[] a)
{
foreach (int x in a)
rtbKetQua.Text += x.ToString() + ' ';
}
private void btnMangMoi_Click(object sender, EventArgs e)
{
int n ;
n = giatri();
a = new int[n];
taomang(a);
xuatmanggoc(a);
khoahieulucbuttion(true);
}
private void btnTimKiem_Click(object sender, EventArgs e)
{
try
{
int vt,x;
x = giatri();
vt = timkiem(a, x);
if (vt!=-1)
{
vt+=1;
MessageBox.Show("Tìm thấy tại vị trí thứ " + vt.ToString(),
"Thông báo", MessageBoxButtons.OK);
}
else
MessageBox.Show("Không tìm thấy", "Thông báo",
MessageBoxButtons.OK);
}
catch
{
MessageBox.Show("Bạn chưa nhập dữ liệu.", "THÔNG BÁO", MessageBoxButtons.OK,
MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
}
}
int timkiem(int[] a, int x)
{
int vt = -1;
for (int i = 0; i < a.Length; i++)
{
if (a[i] == x)
{
vt = i;
break;
}
}
return vt;
}
private void btnClear_Click(object sender, EventArgs e)
{
rtbMangGoc.Clear();
rtbKetQua.Clear();
khoahieulucbuttion(false);
}
private void btnXoa_Click(object sender, EventArgs e)
{
int x,i;
x=giatri();
try
{
for (i = x; i < a.Length - 1; i++)
{
a[1] = a[i + 1];
Array.Resize(ref a,a.Length-1);
xuatmangkq(a);
}
}
catch
{
MessageBox.Show("Bạn chưa nhập dữ liệu", "Thông báo", MessageBoxButtons.OK,
MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
}
khoahieulucbuttion(false);
}
private void btnDaoNguoc_Click(object sender, EventArgs e)
{
int i=0;
int j = a.Length - 1;
int tam;
do
{
tam = a[j];
a[j] = a[i];
a[i] = tam;
i++;
j--;
}
while (i < a.Length / 2);
xuatmangkq(a);
}
}
}
Bạn đang đọc truyện trên: AzTruyen.Top