-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForm_AppMain.cs
More file actions
119 lines (100 loc) · 3.67 KB
/
Form_AppMain.cs
File metadata and controls
119 lines (100 loc) · 3.67 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
namespace ExerciseApp
{
public partial class Form_AppMain : Form
{
private Button currentButton;
private Color highlight = Color.FromArgb(198, 52, 149);
private Form activeForm; // Used to open the subforms
private string username;
private int userId;
public Form_AppMain(int user_id, string username)
{
InitializeComponent();
this.username = username;
this.userId = user_id;
}
private void Form_AppMain_Load(object sender, EventArgs e)
{
button_Home.PerformClick();
label_TabTitle.Text = "Welcome Back " + username;
}
/// <summary>
/// Sets a button to be highlighted.
/// </summary>
private void buttonToHighlighted(object buttonSender)
{
if (buttonSender != null)
{
if (currentButton != (Button)buttonSender)
{
buttonToDefault();
currentButton = (Button)buttonSender;
currentButton.BackColor = highlight;
currentButton.Font = new Font("Century Gothic", 12.25F, FontStyle.Regular);
}
}
}
/// <summary>
/// Resets all buttons on the sidebar to their default style.
/// </summary>
private void buttonToDefault()
{
foreach (Control button in panel_SideBar.Controls)
{
if (button.GetType() == typeof(Button))
{
button.BackColor = Color.Transparent;
button.Font = new Font("Century Gothic", 11.25F, FontStyle.Regular);
}
}
}
public void button_Home_Click(object sender, EventArgs e)
{
OpenChildForms(new AppMain_ChildForms.Form_Home(this, userId), sender);
}
public void button_AddWorkout_Click(object sender, EventArgs e)
{
OpenChildForms(new AppMain_ChildForms.Form_AddWorkout(userId), sender);
}
public void button_Calories_Click(object sender, EventArgs e)
{
OpenChildForms(new AppMain_ChildForms.Form_CalorieTracker(), sender);
}
public void button_Trends_Click(object sender, EventArgs e)
{
OpenChildForms(new AppMain_ChildForms.Form_Trends(), sender);
}
public void button_Steps_Click(object sender, EventArgs e)
{
OpenChildForms(new AppMain_ChildForms.Form_StepTracker(userId), sender);
}
private void Form_AppMain_FormClosed(object sender, FormClosedEventArgs e)
{
Application.Exit();
}
/// <summary>
/// Opens a child form relating the the button the user selected
/// </summary>
/// <param name="childForm"></param>
/// <param name="buttonSender"></param>
private void OpenChildForms(Form childForm, object buttonSender)
{
if (activeForm != null)
{
activeForm.Close(); // Close any previous child form
}
buttonToHighlighted(buttonSender);
// Set child form to display in the center panel and open child form
activeForm = childForm;
childForm.TopLevel = false;
childForm.FormBorderStyle = FormBorderStyle.None;
childForm.Dock = DockStyle.Fill;
this.panel_TabForms.Controls.Add(childForm);
this.panel_TabForms.Tag = childForm;
childForm.BringToFront();
childForm.Show();
label_TabTitle.Text = childForm.Text.ToUpper();
}
}
}