2017-04-10 39 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。任何时候你想在不同的线程中改变一些控件的内容,比如在一个定时器事件中。