CS0120: An object reference is required for the nonstatic field, method, or property 'foo'

前端 未结 7 1088
挽巷
挽巷 2020-11-21 04:34

Consider:

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            


        
7条回答
  •  终归单人心
    2020-11-21 05:08

    Credit to @COOLGAMETUBE for tipping me off to what ended up working for me. His idea was good but I had a problem when Application.SetCompatibleTextRenderingDefault was called after the form was already created. So with a little change, this is working for me:

    
    static class Program
    {
        public static Form1 form1; // = new Form1(); // Place this var out of the constructor

    /// /// The main entry point for the application. /// [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(form1 = new Form1()); } }

提交回复
热议问题