To Do List App (GUI) using C#

To Do List App:

App link here to download and use:- Download Link

 App UI:



This is made with C#.Net in visual studio, It is a windows forms application.


Source Code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace ToDoList2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(txtTask.Text))
            {
                clbTasks.Items.Add(txtTask.Text);
                txtTask.Clear();
            }

            else {
                MessageBox.Show("Please enter a task","ERROR",MessageBoxButtons.OK,MessageBoxIcon.Warning);
            }
        }

        private void btnRemove_Click(object sender, EventArgs e)
        {
            if (clbTasks.SelectedItem != null)
            {
                clbTasks.Items.Remove(clbTasks.SelectedItem);
            }
            else {
                MessageBox.Show("Please select a task to remove","ERROR",MessageBoxButtons.OK,MessageBoxIcon.Warning);
            }
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            File.WriteAllLines("tasks.txt",clbTasks.Items.Cast<string>());
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            string filePath = "tasks.txt";

            if (File.Exists(filePath)) {
                string[] tasks = File.ReadAllLines(filePath);

                foreach (string task in tasks) {
                    clbTasks.Items.Add(task);
                }
            }
        }

        private void txtTask_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter) {
                btnAdd.PerformClick();
                e.Handled = true;
                e.SuppressKeyPress = true;
            }
        }

        private void clbTasks_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Delete) {
                btnRemove.PerformClick();
                e.Handled = true;
                e.SuppressKeyPress = true;
            }
        }

        private void txtTask_Enter(object sender, EventArgs e)
        {
            if (txtTask.Text == "enter your task") {
                txtTask.Text = "";
            }
        }

        private void txtTask_Leave(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(txtTask.Text)) {
                txtTask.Text = "enter your task";
            }
        }

        
    }
}

Comments

Popular posts from this blog

AI and Human Evolution

Snake Game using JAVA