-
Notifications
You must be signed in to change notification settings - Fork 0
/
TaxAppForm.cs
79 lines (67 loc) · 2.61 KB
/
TaxAppForm.cs
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
// Auth: John O'Neal
// Date: 04/03/2024
// Desc: The main form for the tax application. This form is the entry point for the application and contains the main logic for switching between different user controls.
using System.Windows.Forms;
using TaxApp_v2.Admin_User_Controls;
namespace TaxApp_v2
{
public partial class TaxAppForm : Form
{
// Keep track of the current UserControl being displayed on the form
private UserControl currentControl;
private Dictionary<string, UserControl> controls = new Dictionary<string, UserControl>();
public TaxAppForm()
{
InitializeComponent();
// Create the UserControls and add them to the dictionary
controls.Add("Login", new LoginControl());
controls.Add("Registration", new RegistrationControl());
controls.Add("Dashboard", new DashboardControl());
// Show the LoginControl when the form is loaded
SwitchTo("Login");
}
public void SwitchTo(string controlName)
{
// Remove the current UserControl
if (currentControl != null)
this.Controls.Remove(currentControl);
// Get the new UserControl from the dictionary
currentControl = controls[controlName];
// Add the new UserControl to the form
this.Controls.Add(currentControl);
if (controlName == "Dashboard")
{
currentControl.Dock = DockStyle.Fill;
}
else
{
Utils.CenterControl(currentControl);
// focus username
if (controlName == "Login")
{
((LoginControl)currentControl).FocusUsername();
}
else if (controlName == "Registration")
{
((RegistrationControl)currentControl).FocusUsername();
}
}
}
// Getter for current UserControl
public UserControl CurrentControl
{
get { return currentControl; }
}
private void TaxAppForm_FormClosing(object sender, FormClosingEventArgs e)
{
// Display a message box and get the user's response
DialogResult result = MessageBox.Show(
"Are you sure you want to exit?", "Confirm Exit", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
// Cancel the closing operation if the user clicked No
if (result == DialogResult.No)
{
e.Cancel = true;
}
}
}
}