Search code examples
c#winformsfullscreen

Setting formBorderStyle to None fails with error FormBorderStyle is used as a variable


System.Windows.Forms.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
WindowState = System.Windows.WindowState.Maximized;

I am trying to set the FormBorderStyle to None (to get fullscreen) but I I always get an error that the

FormBorderStyle is used as a variable.

enter image description here


Solution

  • See this line of code that you have. This line works because it is saying that the WindowState is assigned the value on the right.

    WindowState = System.Windows.WindowState.Maximized;
    

    Then you have this line of code:

    System.Windows.Forms.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
    

    That is similar to doing something like this:

    int = int; // will not work  
    

    Both on the left and right side you have a type. You need to change it to this:

    FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
    

    Now you are saying that FormBorderStyle of current window is the value on the right.

    EDIT

    In WPF you will do it like this:

    this.WindowStyle = WindowStyle.None;