2017-04-10 21 views
-3

我正在一個項目中,我有一個計時器。當計時器結束時,我正在做一些說明,並將按鈕的可見性設置爲true。 此行的結果出現錯誤button.visible = true意外錯誤

"Invalid parameter" in Program.cs at line 
Application.Run(new Main()); 

我不知道如何在一個按鈕的可見性的簡單變化可以在此處導致錯誤。

下面是代碼:

private void timerDuring_Tick(object sender, EventArgs e) 
{ 
    if (timeLeft > 0) 
    { 
     timeLeft = timeLeft - 1; 
     labelTime.Text = timeLeft +""; 
    } 
    else 
    { 
     TimerDuring.Stop(); 
     labelTime.Visible = false; 
     VCapture.Dispose(); 
     VCapture = null; 

     capture.Dispose(); 

     CamImageBox.Visible = false; 

     String pathVideo = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "video.avi"); 
     WMP.Visible = true; 
     WMP.URL = pathVideo; //Emplacement de la video apres la capture 
     WMP.uiMode = "none"; 
     WMP.settings.setMode("loop", true); 
     WMP.Ctlcontrols.play(); // chaque image a recup 

     btnDecoupe.Visible = true; // ERROR caused HERE 
     btnReplay.Visible = true; // ERROR caused HERE 
    } 
} 

在哪裏,由Visual Studio所指示的錯誤的Program.cs:

static class Program 
{ 
    /// <summary> 
    /// Point d'entrée principal de l'application. 
    /// </summary> 
    [STAThread] 
    static void Main() 
    { 
     Application.EnableVisualStyles(); 
     Application.SetCompatibleTextRenderingDefault(false); 
     Application.Run(new Main()); 
    } 
} 

當我改變Visibilityfalse它的工作原理,誤差僅爲拋出當我將其更改爲true時。

我的窗體的名稱是「Main.cs」在UI線程

+1

你正在使用哪個計時器? –

+0

c#Timer控件TimerDuring –

+0

它是一個Windows.Forms.Timer,System.Threading.Timer或System.Timer –

回答

0

你應該只操縱控制。你可以通過調用Control.Invoke()

Invoke(new Action(() => 
    { 
     btnDecoupe.Visible = true; 
     btnReplay.Visible = true; 
    })); 

做同樣爲他們設置爲false。任何時候你想在不同的線程中改變一些控件的內容,比如在一個定時器事件中。