При установке DoubleBuffered = true в подчиненной форме, System.ArgumentException вызывается в Program.cs (System.Drawing.dll) - PullRequest
1 голос
/ 21 апреля 2019

Я пытаюсь решить некоторые проблемы с мерцанием в событии Paint, установив DoubleBuffered = true в форме, которая открывается, когда пользователь нажимает кнопку в основной форме. Однако, как только новая форма загружается, я получаю исключение в Program.cs

"System.ArgumentException occurred in System.Drawing.dll"


"System.ArgumentException: 'Parameter is not valid.'"

в файле Program.cs

Я могу подтвердить, что метод Paint не вызывается, когда появляется ошибка, и кажется, что ошибка возникает, когда конструктор формы завершен. Я устанавливаю DoubleBuffered = True в свойствах Дизайнера.

Первая форма, вызывающая вторую форму (Form1.cs)

if(toggleButton())
            {
                int numThreads = Int32.Parse(numeric_threads.Value.ToString());


                List<Section> sections = new List<Section>();
                sections.Add(new Section(0, 0, prevScreen.Bounds.Width, 100, checkbox_UseAudio.Checked, false, Int32.Parse(numeric_horizontalLEDs.Value.ToString()))); //Top
                sections.Add(new Section(0, prevScreen.Bounds.Height - 100, prevScreen.Bounds.Width, 100, false, false, Int32.Parse(numeric_horizontalLEDs.Value.ToString()))); //Bottom
                sections.Add(new Section(0, 0, 100, prevScreen.Bounds.Height, false, true, Int32.Parse(numeric_verticalLEDs.Value.ToString()))); //Left
                sections.Add(new Section(prevScreen.Bounds.Width - 100, 0, 100, prevScreen.Bounds.Height, false, true, Int32.Parse(numeric_verticalLEDs.Value.ToString())));//  Right
                dial = new LEDSimulate(pathScript, pathPython, formInst, sections, combo_monitor.SelectedIndex, numThreads);
                dial.Show();
            }
            else
            {
                button_flag = true;
                //Kill all the threads by closing
                dial.Close();
            }

Вторая форма, которая открывается из первой формы и приводит к ошибке (LEDSimulate.cs)

        public LEDSimulate(string pathScript, string pathPython, Form1 formInst, List<Section> sections, int mon, int numThreads)
        {
            InitializeComponent();
            instance = this;

            this.TransparencyKey = (BackColor);
            this.sections = sections;
            this.procs = new List<Process>();
            this.formInst = formInst;

            //Initialize timer to tick every 30 seconds to update UI
            timer_updatePaint.Interval = 33;

            //Load with dummy data to update later
            Pen dummy_pen = new Pen(Color.FromArgb(0, 0, 0, 0));
            foreach (Section s in sections)
            {
                for(int i = 0; i<s.subSections; i++)
                {
                    paintList.Add(new PaintForm(dummy_pen, 0, 0, 0, 0));
                }
            }
            Console.WriteLine("Finished adding and starting");
            timer_updatePaint.Start();
            //-----Once this is done, the error occurs------
        }

Program.cs

static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1()); //Error pops up on this line
        }
    }
        private void timer_updatePaint_Tick(object sender, EventArgs e)
        {
            this.Refresh();
        }

        protected override CreateParams CreateParams
        {
            get
            {
                CreateParams cp = base.CreateParams;
                cp.ExStyle |= 0x02000000;  // Turn on WS_EX_COMPOSITED
                return cp;
            }
        }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...