X 분 이내에 텍스트가 저장되지 않았고 사용자가 앱을 종료하려는 경우 메시지 상자를 보내려면 어떻게해야합니까?

카일라

다음은 의사 코드입니다.

  private void ForgetSave()
{    
   if (the SaveRegularly method hasn't been used within 3 mins)

      MessageBox.Show("Would you like to save any changes before closing?")

  ......... the code continues.
}  
   else
{  
    this.close();
}

아무도 if 문의 첫 줄을 작성하는 방법을 알고 있습니까?

다니엘 에프렌

Ahmed가 메시지를 표시해야 할 때를 알기 위해 타이머와 플래그를 사용할 수 있다고 제안했듯이 시작하는 데 필요한 코드를 남겼습니다.

    private const int SAVE_TIME_INTERVAL = 3 * 60 * 1000;
    private bool iWasSavedInTheLastInterval = true;
    private System.Windows.Forms.Timer timer;

    public Form1()
    {
        InitializeComponent();
        //Initialize the timer to your desired waiting interval
        timer = new System.Windows.Forms.Timer();
        timer.Interval = SAVE_TIME_INTERVAL;
        timer.Tick += Timer_Tick;
        timer.Start();
    }

    private void Timer_Tick(object sender, EventArgs e)
    {
        //If the timer counts that amount of time we haven't saved in that period of time
        iWasSavedInTheLastInterval = false;
    }

    private void Form1_FormClosing(object sender, FormClosingEventArgs e)
    {
        if (iWasSavedInTheLastInterval == false)
        {
            MessageBox.Show("Would you like to save any changes before closing?");
        }
    }

    private void btnSave_Click(object sender, EventArgs e)
    {
        //If a manual save comes in then we restart the timer and set the flag to true
        iWasSavedInTheLastInterval = true;
        timer.Stop();
        timer.Start();
    }

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

Related 관련 기사

뜨겁다태그

보관