-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathForm1.vb
More file actions
159 lines (123 loc) · 4.59 KB
/
Form1.vb
File metadata and controls
159 lines (123 loc) · 4.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
Imports System.IO
Public Class Form1
Dim font_name As String = "Source Sans Pro"
Dim todolist As New List(Of CheckBox)
Dim Tremain As Integer = 0
Dim Tdone As Integer = 0
Dim file_name As String = "task_data.txt"
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
AddButton.BackColor = Color.FromArgb(0, 125, 212)
Bremove_checked.BackColor = Color.FromArgb(0, 125, 212)
Ball_clear.BackColor = Color.FromArgb(0, 125, 212)
ProgressBar1.ForeColor = Color.FromArgb(0, 125, 212)
task_panel.BackColor = Color.White
Panel2.BackColor = Color.White
Panel3.BackColor = Color.White
MenuStrip1.BackColor = Color.White
End Sub
'update status
Private Sub update_status()
status.Text = String.Format("{0} of {1} tasks done", Tdone, Tremain)
Try
ProgressBar1.Value = (100 \ Tremain) * Tdone
Catch ex As Exception 'Solve Divide By 0 Error
ProgressBar1.Value = 0
End Try
End Sub
'toggle Strickthrough
Private Sub toggle_strikethrough(sender As Object, e As EventArgs)
If sender.CheckState = CheckState.Checked Then
sender.Font = New Font(font_name, sender.font.size, FontStyle.Strikeout)
'Status value Update
Tdone = Tdone + 1
Else
sender.Font = New Font(font_name, sender.font.size, FontStyle.Regular)
'Status value Update
Tdone = Tdone - 1
End If
update_status()
End Sub
'Add List
Private Sub add_task(title As String, Optional checked As Boolean = False, Optional foropen As Boolean = False)
Dim CB As New CheckBox
CB.AutoSize = True
CB.Padding = New Padding(8, 8, 0, 8)
CB.BackColor = Color.FromArgb(0, 125, 212)
CB.ForeColor = Color.White
CB.Dock = DockStyle.Top
CB.Text = title
CB.Checked = checked
' Font
CB.Font = New Font(font_name, 15, FontStyle.Regular)
'Add Event handler
AddHandler CB.CheckedChanged, AddressOf toggle_strikethrough
If foropen Then
toggle_strikethrough(CB, New EventArgs)
End If
'Status value Update
Tremain = Tremain + 1
update_status()
task_panel.Controls.Add(CB)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles AddButton.Click
If input_box.Text = "" Then
Exit Sub
End If
add_task(input_box.Text)
' clear text box
input_box.Text = ""
End Sub
Private Sub Remove_Checked(sender As Object, e As EventArgs) Handles Bremove_checked.Click
For Each CB As CheckBox In task_panel.Controls
If CB.Checked = True Then
todolist.Add(CB)
Tremain = Tremain - 1
Tdone = Tdone - 1
End If
Next
For Each CB As CheckBox In todolist
task_panel.Controls.Remove(CB)
Next
todolist.Clear()
update_status()
End Sub
Private Sub All_clear(sender As Object, e As EventArgs) Handles Ball_clear.Click
task_panel.Controls.Clear()
Tremain = 0
Tdone = 0
update_status()
End Sub
Private Sub save_list(ByVal file_name As String)
Dim wfile As StreamWriter = New StreamWriter(Directory.GetCurrentDirectory() + "\" + file_name)
Dim state As String
For Each CB As CheckBox In task_panel.Controls
If CB.Checked = True Then
state = "1 "
Else
state = "0 "
End If
wfile.WriteLine(state + CB.Text)
Next
wfile.Close()
End Sub
Private Sub open_list(ByVal file_name As String)
All_clear(New Object, New EventArgs)
Dim rfile As StreamReader = New StreamReader(Directory.GetCurrentDirectory() + "\" + file_name)
Dim line As String = rfile.ReadLine()
While (line <> Nothing)
If line.Substring(0, 1) = "1" Then
add_task(line.Substring(1, Len(line) - 1), True, True)
Else
add_task(line.Substring(1, Len(line) - 1))
End If
line = rfile.ReadLine()
End While
rfile.Close()
End Sub
Private Sub SaveToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles SaveToolStripMenuItem.Click
save_list(file_name)
End Sub
Private Sub OpenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles OpenToolStripMenuItem.Click
open_list(file_name)
End Sub
End Class