今天要來介紹讓c#視窗整個程式重新啟動的方法,非常的簡單只要兩個步驟就行

~~~分割線醬(趴<(_ _)>~~~

第1步

要讓程式重新啟動,首先先把以下的方法貼在Form的class下


 private void Restart()
        {
            System.Threading.Thread thtmp = new System.Threading.Thread(new
            System.Threading.ParameterizedThreadStart(run));

            object appName = Application.ExecutablePath;
            System.Threading.Thread.Sleep(2000);
            thtmp.Start(appName);
        }

        private void run(Object obj)
        {
            System.Diagnostics.Process ps = new System.Diagnostics.Process();
            ps.StartInfo.FileName = obj.ToString();
            ps.Start();
        }


第2步

然後在把下面這段程式碼放在你想要啟動的按鈕或是物件中


 Application.ExitThread();
            Restart();


這樣子當你按下這個按鈕/物件的時候,整個程式就會重新啟動一遍,是不是很簡單~ξ( ✿>◡❛)

arrow
arrow

    星夢月影 發表在 痞客邦 留言(0) 人氣()