Write a small but complete budget apps of your choice of platform. - it must have a…
- User
Write a small but complete budget apps of your choice of platform.
- it must have a clean gui
- needs to run in windows after complie
- Assistant
Write a small but complete budget apps of your choice of platform.
Sure! Below is a simple budget application written in C# using Windows Forms. This application allows users to add income and expense items, displays them in a list, and calculates the total income, total expenses, and the remaining balance. The GUI is designed to be clean and user-friendly.
Prerequisites:
Create a New Project:
Design the User Interface:
TextBoxes:
txtDescription for the description of the item.txtAmount for the amount of the item.ComboBox:
cmbType to select "Income" or "Expense".Buttons:
btnAdd to add the item to the budget.btnClear to clear all entries.ListView:
lvItems to display the list of income and expenses.Labels:
lblTotalIncome to display the total income.lblTotalExpenses to display the total expenses.lblBalance to display the remaining balance.Place the controls neatly on the form to ensure a clean GUI. Group related controls, use appropriate spacing, and align controls for a professional look.
Below is the complete code for the budget application.
using System;
using System.Windows.Forms;
namespace BudgetApp
{
public partial class Form1 : Form
{
decimal totalIncome = 0;
decimal totalExpenses = 0;
public Form1()
{
InitializeComponent();
InitializeCustomComponents();
}
private void InitializeCustomComponents()
{
cmbType.Items.Add("Income");
cmbType.Items.Add("Expense");
cmbType.SelectedIndex = 0;
// Setup ListView columns
lvItems.Columns.Add("Type", 80);
lvItems.Columns.Add("Description", 200);
lvItems.Columns.Add("Amount", 100, HorizontalAlignment.Right);
lvItems.View = View.Details;
lvItems.FullRowSelect = true;
UpdateTotals();
}
private void btnAdd_Click(object sender, EventArgs e)
{
string type = cmbType.SelectedItem.ToString();
string description = txtDescription.Text.Trim();
string amountText = txtAmount.Text.Trim();
if (string.IsNullOrEmpty(description) || string.IsNullOrEmpty(amountText) || !decimal.TryParse(amountText, out decimal amount))
{
MessageBox.Show("Please enter valid data.", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
if (amount < 0)
{
MessageBox.Show("Amount cannot be negative.", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
// Add item to ListView
ListViewItem item = new ListViewItem(type);
item.SubItems.Add(description);
item.SubItems.Add(amount.ToString("C"));
lvItems.Items.Add(item);
// Update totals
if (type == "Income")
{
totalIncome += amount;
}
else
{
totalExpenses += amount;
}
UpdateTotals();
ClearInputFields();
}
private void UpdateTotals()
{
lblTotalIncome.Text = $"Total Income: {totalIncome:C}";
lblTotalExpenses.Text = $"Total Expenses: {totalExpenses:C}";
decimal balance = totalIncome - totalExpenses;
lblBalance.Text = $"Balance: {balance:C}";
}
private void ClearInputFields()
{
txtDescription.Clear();
txtAmount.Clear();
cmbType.SelectedIndex = 0;
txtDescription.Focus();
}
private void btnClear_Click(object sender, EventArgs e)
{
lvItems.Items.Clear();
totalIncome = 0;
totalExpenses = 0;
UpdateTotals();
}
}
}
Make sure your Form1.Designer.cs includes the component declarations and initialization code. If you used the Designer to add controls, this code is auto-generated.
partial class Form1
{
private System.ComponentModel.IContainer components = null;
private System.Windows.Forms.TextBox txtDescription;
private System.Windows.Forms.TextBox txtAmount;
private System.Windows.Forms.ComboBox cmbType;
private System.Windows.Forms.Button btnAdd;
private System.Windows.Forms.Button btnClear;
private System.Windows.Forms.ListView lvItems;
private System.Windows.Forms.Label lblTotalIncome;
private System.Windows.Forms.Label lblTotalExpenses;
private System.Windows.Forms.Label lblBalance;
// ... (Designer generated code for InitializeComponent method)
}
Adding Items:
Displaying Items:
ListView control displays all added items with their type, description, and formatted amount.Calculating Totals:
Total Income - Total Expenses.Clearing Data:
Compile and Run:
Executable File:
BudgetApp.exe) can be found in the bin\Debug or bin\Release folder of your project directory.Since I can't display images, here's a description of the expected GUI:
At the top, there are input fields:
Below the input fields, there's a ListView displaying the added items in three columns: Type, Description, Amount.
At the bottom, there are labels showing:
There's also a "Clear" button to reset the application.
Error Handling:
Enhancements:
Cross-Platform GUI Libraries:
Feel free to customize and expand upon this basic budget application to suit your needs. Let me know if you need further assistance or have any questions!
Not yet included in a published release.