我的表单顶部有一个MenuStrip。我只有一个名为Dates的ToolStripMenuItem。我编写的代码在" Add"单击按钮,在"日期"下面添加一个新菜单项。此菜单项通过连接存储用户输入的一些变量来命名。以下是我为"添加"按钮单击事件。这一切都有效,但我希望显示当click事件碰巧也保存到子菜单项时在标签中显示的相同信息。所以我希望能够单击创建的子菜单项,并且能够在单击“添加”按钮时查看保存到的输入。
private: System::Void btnAdd_Click(System::Object^ sender, System::EventArgs^ e)
{
//add the input to the variables
String^ month = txtMonth->Text;
String^ day = txtDay->Text;
String^ year = txtYear->Text;
double tips = Double::Parse(txtTips->Text);
//make sure the date input is correct
if (txtMonth->Text == "" || txtDay->Text == "" || txtYear->Text == "" || Double::Parse(month) < 1 || Double::Parse(month) > 12
|| Double::Parse(day) < 1 || Double::Parse(day) > 31 /*|| Double::Parse(year)!=*/)
{
//show message box
MessageBox::Show("Please enter the date in the correct format.", "Error", MessageBoxButtons::OK,
MessageBoxIcon::Error);
//clear the boxes
txtMonth->Clear();
txtDay->Clear();
txtYear->Clear();
}
else
{
//for the menu bar
String^ date = month + "/" + day + "/" + year;
datesToolStripMenuItem->DropDownItems->Add(date)->Equals(date);
//print to label
lblPrint->Text = month + "/" + day + "/" + year + " - " + tips.ToString("c");
//clear the boxes
txtMonth->Clear();
txtDay->Clear();
txtYear->Clear();
txtTips->Clear();
}
}
FYI。我还没有编写任何代码来做我想做的事情。我只是不知道从哪里开始,所以我在此之前分享了我所拥有的。