In this article, we develop an income-expense tracking application using C# Windows Forms. The application includes adding income and expenses, listing, and balance calculation.
Step 1: Creating the Project and Designing the Interface
First, open Visual Studio and create a new Windows Forms project. Name your project, then switch to form design.
In the form design, add labels, text boxes, and buttons so the user can add income and expenses. Here is an example interface:
- Label: "Add Income"
- Text Box: For income amount
- Text Box: For income description
- Date Picker: For income date
- Button: "Add Income"
Similarly, add interface elements for "Add Expense".
Step 2: Creating the Income and Expense Classes
Create a C# class and define the Income and Expense classes. These classes should have properties such as amount, description, and date.
class Gelir
{
public decimal Miktar { get; set; }
public string Aciklama { get; set; }
public DateTime Tarih { get; set; }
}
class Gider
{
public decimal Miktar { get; set; }
public string Aciklama { get; set; }
public DateTime Tarih { get; set; }
}
Step 3: Form Coding and Creating Functions
In the form's code-behind, define the income and expense collections using the classes we created:
List<Gelir> gelirListesi = new List<Gelir>();
List<Gider> giderListesi = new List<Gider>();
Let's code the click events for the buttons to add income and expenses:
private void btnGelirEkle_Click(object sender, EventArgs e)
{
Gelir yeniGelir = new Gelir
{
Miktar = Convert.ToDecimal(txtGelirMiktar.Text),
Aciklama = txtGelirAciklama.Text,
Tarih = dateGelirTarih.Value
};
gelirListesi.Add(yeniGelir);
// Listeyi güncelleme işlevini çağır
}
private void btnGiderEkle_Click(object sender, EventArgs e)
{
Gider yeniGider = new Gider
{
Miktar = Convert.ToDecimal(txtGiderMiktar.Text),
Aciklama = txtGiderAciklama.Text,
Tarih = dateGiderTarih.Value
};
giderListesi.Add(yeniGider);
// Listeyi güncelleme işlevini çağır
}
Let's create a function to update the income and expense list:
private void ListeyiGuncelle()
{
// Gelir listesini güncelleme işlemleri
// Gider listesini güncelleme işlemleri
// Toplam bakiye hesaplama
}
Step 4: Conclusion and Testing
Edit the functions you created and bind them to the interface elements on the form.
Test your application. Add income and expenses, and check the lists and total balance.
That's it! We have created the "Income-Expense Tracking Application" project step by step. You can enhance this project by adding more features and making a more user-friendly interface.