Cấp bậc tác giả:

DOTNET

Xây dựng từ điển đơn giản

Được viết bởi QuangIT ngày 23/09/2012 lúc 03:15 PM
- Khi nhập vào combobox 1 từ cần tra thì chương trình sẽ dò tìm đến chữ nào khớp với ký tự gần nhất - Khi nhấn nút Enter hoặc Doubleclick vào từ cần tra thì nghĩa tương ứng của từ sẽ hiển thị vào textbox bên phải tương ứng. - Danh sách các từ lưu sẵn vào object (word)
  • 0
  • 10878

Xây dựng từ điển đơn giản

Mục đích:

Sử dụng Arraylist,

Yêu cầu:

Xây dựng từ điển đơn giản

- Khi nhập vào combobox 1 từ cần tra thì chương trình sẽ dò tìm đến chữ nào khớp với ký tự gần nhất

- Khi nhấn nút Enter hoặc Doubleclick vào từ cần tra thì nghĩa tương ứng của từ sẽ hiển thị vào textbox bên phải tương ứng.

- Danh sách các từ lưu sẵn vào object (word) 


using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.Collections;

namespace Bai06

{


public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private ArrayList arr;

private void Form1_Load(object sender, EventArgs e)

{

arr = new ArrayList();

ThemDuLieuVaoArray();

HienThiArrLenListview();

txtSearch.Focus();

}

void ThemDuLieuVaoArray()

{

arr.Add("student");

arr.Add("Sinh Viên,Học Sinh");

arr.Add("teacher");

arr.Add("Giáo Viên,Giảng Viên");

arr.Add("worker");

arr.Add("Công Nhân");

arr.Add("mouse");

arr.Add("Con Chuột");

arr.Add("stupid");

arr.Add("Ngu Ngốc");

}

void HienThiArrLenListview()

{

for (int i = 0; i < arr.Count; i = i + 2)

{

listBox1.Items.Add(arr[i].ToString());

}

}

private void btnThoat_Click(object sender, EventArgs e)

{

this.Close();

}

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)

{

txtTiengAnh.Text = listBox1.SelectedItem.ToString();

for (int i = 0; i < arr.Count; i = i + 2)

{

if (arr[i].Equals(listBox1.SelectedItems[0].ToString()))

{


richTextBox1.Text = arr[i + 1].ToString();

}


}

}

private void txtSearch_TextChanged(object sender, EventArgs e)

{

for (int i = 0; i < arr.Count; i = i + 2)

{

int x = txtSearch.Text.Length;

if (arr[i].ToString().Substring(0, x).Equals(txtSearch.Text))

{

int y = arr[i].ToString().Length;

txtTiengAnh.Text = arr[i].ToString();

richTextBox1.Text = arr[i + 1].ToString();

//txtTiengAnh.Select(x, y - x);

break;

}

}

}

}

}

Nguồn bài viết: Dngaz.com

BÌNH LUẬN BÀI VIẾT

Bài viết mới nhất

LIKE BOX

Bài viết được xem nhiều nhất

HỌC HTML