Griffin Premium
Programlama, Windows Form Örnekleri, C# İngilizce Türkçe Sözlük, C# Sözlük, C# Türkçe İngilizce Sözlük
Bu örneğimizde daha önceden yapmış olduğumuz Türkçe-İngilizce sözlük örneğine ek olarak eklediğimiz radiobutton seçeneğine göre İngilizce-Türkçe çevirisini de yapan bir uygulama oluşturacağız. Yani kullanıcının seçimine göre Türkçe-İngilizce yada İngilizce-Türkçe Sözlük örneğini oluşturacağız. Form görüntüsü ve kodlar aşağıdaki gibi olacaktır.
C#:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace sozluk
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
OleDbConnection con;
OleDbDataAdapter da;
DataSet ds;
private void Form1_Load(object sender, EventArgs e)
{
con = new OleDbConnection("Provider=Microsoft.ACE.Oledb.12.0;Data Source=dbSozluk.accdb");
da = new OleDbDataAdapter("SElect *from sozluk", con);
ds = new DataSet();
con.Open();
da.Fill(ds, "sozluk");
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
DataView dv = ds.Tables[0].DefaultView;
listBox1.Items.Clear();
textBox2.Clear();
if (radioButton1.Checked)
{
dv.RowFilter = "turkce Like '" + textBox1.Text + "%'";
if (dv.Count > 0)
{
for (int i = 0; i < dv.Count; i++)
{
listBox1.Items.Add(dv[i].Row["turkce"]);
}
}
}
else
{
listBox1.Items.Clear();
textBox2.Clear();
dv.RowFilter = "ingilizce Like '" + textBox1.Text + "%'";
if (dv.Count > 0)
{
for (int i = 0; i < dv.Count; i++)
{
listBox1.Items.Add(dv[i].Row["ingilizce"]);
}
}
}
//dv.RowFilter = string.Format("Ad LIKE '{0}%'", textBox5.Text);
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
DataView dv = ds.Tables[0].DefaultView;
if(radioButton1.Checked)
{
dv.RowFilter = "turkce ='" + listBox1.SelectedItem.ToString() + "'";
textBox2.Text = dv[0].Row["ingilizce"].ToString();
}
else
{
dv.RowFilter = "ingilizce ='" + listBox1.SelectedItem.ToString() + "'";
textBox2.Text = dv[0].Row["turkce"].ToString();
}
}
}
}