C++ C++;计时器、windows窗体、启动按钮单击

C++ C++;计时器、windows窗体、启动按钮单击,c++,windows,forms,button,timer,C++,Windows,Forms,Button,Timer,我需要你的帮助。我试图在VisualStudio 2010中使用Windows窗体在C++中构建应用程序。这个应用程序会稍微复杂一点,但现在我遇到的问题是如何启动一个计时器,我在windows窗体上拖拽了一个名为“start”的普通按钮,出于某些原因,例如,timer1.start()timer1.Stop()或代替.,->不工作,我得到的错误有一个类或其他东西在左边的开始和停止。我也不知道为什么我的计时器会滴答滴答地响一次,我会将秒数初始化为1,但如果这也可以避免,那么它将保持在0:0就太好了

我需要你的帮助。我试图在VisualStudio 2010中使用Windows窗体在C++中构建应用程序。这个应用程序会稍微复杂一点,但现在我遇到的问题是如何启动一个计时器,我在windows窗体上拖拽了一个名为“start”的普通按钮,出于某些原因,例如,timer1.start()timer1.Stop()或代替.,->不工作,我得到的错误有一个类或其他东西在左边的开始和停止。我也不知道为什么我的计时器会滴答滴答地响一次,我会将秒数初始化为1,但如果这也可以避免,那么它将保持在0:0就太好了。非常感谢。我只是把相关的代码,我有其他的东西,如文本框等。我设法使一个文本框只接受数字,但当我尝试在另一个文本框上相同的代码只接受数字时,我的“设计”面板将不再向我显示windows窗体,并得到一个错误,这将是另一个需要解决的问题。所以,按钮1\u Click()

//
//定时器1
//
此->定时器1->启用=真;
此->定时器1->间隔=1000;
this->timer1->Tick+=gcnewsystem::EventHandler(this,&Form1::timer1\u Tick);
//
//时间
//
此->时间->自动调整大小=真;
此->时间->启用=false;
此->时间->字体=(gcnew System::Drawing::Font)(L“Microsoft Sans Serif”,14.25F,System::Drawing::FontStyle::Regular,System::Drawing::GraphicsUnit::Point,
静态(0);
此->时间->位置=系统::图纸::点(121,24);
此->时间->名称=L“时间”;
此->时间->尺寸=系统::图纸::尺寸(35,24);
此->时间->选项卡索引=0;
此->时间->文本=L“0:0”;
this->Time->Click+=gcnewsystem::EventHandler(this,&Form1::Time\u Click);
#布拉格端区
private:System::Void timer1_Tick(System::Object^sender,System::EventArgs^e){
秒=0;
分钟=0;
//在按下开始按钮时执行
第二++;
如果(秒==60)
{
秒=0;
分钟++;
}
秒=转换::ToString(秒);
Min=转换::ToString(分钟);
时间->文本=分钟+“:”+秒;
std::string afisaj=“您已达到运行时间”;
std::string info=“暂停”;
//std::字符串afisaj;
//std::cout Handled=true;
}
//允许负数
如果(e->KeyChar='-'&&&&!(此->文本框1->文本->包含(“-”)),则为else{
e->Handled=true;
textBox1->Text=“-”+textBox1->Text;
}
//仅接受数字“.”、“-”和退格字符
如果(!Char::IsDigit(e->KeyChar)&&e->KeyChar!=0x08,则为else){
e->Handled=true;
}
}
私有:系统::无效时间\单击(系统::对象^sender,系统::事件参数^e){
}
私有:系统::无效按钮1\u单击(系统::对象^sender,系统::事件参数^e)
{
   //
    // timer1
    //
    this->timer1->Enabled = true;
    this->timer1->Interval = 1000;
    this->timer1->Tick += gcnew System::EventHandler(this, &Form1::timer1_Tick);
    //
    // Time
    //
    this->Time->AutoSize = true;
    this->Time->Enabled = false;
    this->Time->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
    static_cast<System::Byte>(0)));
    this->Time->Location = System::Drawing::Point(121, 24);
    this->Time->Name = L"Time";
    this->Time->Size = System::Drawing::Size(35, 24);
    this->Time->TabIndex = 0;
    this->Time->Text = L"0:0";
    this->Time->Click += gcnew System::EventHandler(this, &Form1::Time_Click);


    #pragma endregion
    private: System::Void timer1_Tick(System::Object^  sender, System::EventArgs^  e) {


    Second = 0;
    Minute = 0;

    //to be executed on pressing the Start Button

    Second++;

    if (Second == 60)
    {
    Second = 0;
    Minute++;
    }
    Sec = Convert::ToString(Second);
    Min = Convert::ToString(Minute);
    Time ->Text = Min + ":" + Sec;

    std::string afisaj = "You have reached elapsed time";
    std::string info = "Paused";

    //std::string afisaj;
                    //std::cout << "Please, enter your full name: ";
                    //std::getline (std::cin,afisaj);
                    //std::cout << "Hello, " << name << "!\n";

           //std::string info;
                    //std::cout << "Please, enter your full name: ";
                    //std::getline (std::cin,info);
                    //std::cout << "Hello, " << name << "!\n";

    if ((Minute == 1) && (Second == 35))
    //MessageBox(NULL,"You have reached elapsed time","Paused",MB_OK);
       MessageBox::Show( "You have reached elapsed time", "Paused",MessageBoxButtons::OK, MessageBoxIcon::Exclamation );

    }


private: System::Void textBox1_KeyPress(System::Object^  sender, System::Windows::Forms::KeyPressEventArgs^  e)
{

    if(e->KeyChar == '.')
{
        if( this->textBox1->Text->Contains(".") && !this->textBox1->SelectedText->Contains(".") )
            e->Handled = true;  
    }
    // Allow negative numbers
    else if(e->KeyChar == '-' && !(this->textBox1->Text->Contains("-"))){
        e->Handled = true;
        textBox1->Text = "-" + textBox1->Text;
    }
    // Accept only digits ".", "-" and the Backspace character
    else if(!Char::IsDigit(e->KeyChar)&& e->KeyChar != 0x08){
        e->Handled = true;
    }

}
private: System::Void Time_Click(System::Object^  sender, System::EventArgs^  e) {
}
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e)
{