Hi. I am attempting to make a GUI program as a personal project in C++ using visual studio. This is what the program does: If you run the program at 2:30pm, the program will check off a box that says "you are in hour two" (because the hour of the day in which you decide to run the program is in the 2th hour). If you run the program at 7:20am, the program will check off a box that says "you are in hour 7" (because the hour of the day in which you decide to run the program is in the 7th hour). Lastly, it has a label at the top of the window will show the current local time.
I know need to make 12 check boxes to represent each hour of the day. I also need to disable the check boxes so that the user can not change the check boxes. Also, the computer needs to check off the box based off of the local time. Lastly, I want a button that will refresh the check boxes based off of the new time and refreshes the label that shows the current local time(ex: If the user opens the app at 8:00pm the check box that says "you are in hour 8" will be checked off. If the user leaves the GUI program on for an hour, the refresh button should check off "you are in hour 9" because by then it will be 9:00pm. Then it should change the label to the new local time).
I don't know some of the syntax in C++ to do set and disable the check buttons. If anyone knows the how to do this, I will greatly appreciate the help.
Here is my code so far:
public:
MyForm(void)
{
InitializeComponent();
//Shows current time in label 2
DateTime datetime = DateTime::Now;
this->label2->Text = datetime.ToString("hh:mm");
checkBox1->Enabled = false; //disables checkbox for hour 1
checkBox2->Enabled = false; //disables checkbox for hour 2
checkBox3->Enabled = false; //disables checkbox for hour 3
checkBox4->Enabled = false; //disables checkbox for hour 4
checkBox5->Enabled = false; //disables checkbox for hour 5
checkBox6->Enabled = false; //disables checkbox for hour 6
checkBox7->Enabled = false; //disables checkbox for hour 7
checkBox8->Enabled = false; //disables checkbox for hour 8
checkBox9->Enabled = false; //disables checkbox for hour 9
checkBox10->Enabled = false; //disables checkbox for hour 10
checkBox11->Enabled = false;//disables checkbox for hour 11
checkBox12->Enabled = false; //disables checkbox for hour 12
//
//TODO: Add the constructor code here
//
}
//_______________________________________________________________
/*Here is what I have done for hour 1. If I can get this to work then I can do the same for the other check boxes.*/
private: System::Void checkBox1_CheckedChanged(System::Object^ sender, System::EventArgs^ e) {
//Controls time for binary clock
time_t currentTime;
struct tm* localTime;
time(&tTime); // Get the current time
localTime = localtime(&tTime); // Convert the current time to the local time
int Hour = localTime->tm_hour % 12; //Must mod time by 12 to get standard time
if (Hour = 1) {
checkBox1->Checked = true; //checks off box
}
}
//__________________________________________________________
/*This part of the code is for the refresh button. Right now, all it does is updates
the current time in label 2 but does not update the check boxes to reflect the time*/
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
DateTime datetime = DateTime::Now;
this->label2->Text = datetime.ToString("hh:mm");
}