Monday, March 05, 2018

WinForm bei Bedarf in Gui Task zurück

wichtig: Gui im Gui Thread öffnen !

        /// <summary>
        /// 1) check if correct thread, if not call in correct thread
        /// 2) sets Text of Control c
        /// </summary>
        /// <param name="c"></param>
        /// <param name="text"></param>
        public void _SetText(Control c, string text)
        {
            if (this.InvokeRequired)
                this.Invoke(new Action<Control, string>(_SetText), c, text);
            else
                c.Text = text;
        }



        public void _SetMax(int max)
        {
            if (this.InvokeRequired)
                this.Invoke(new Action<int>(_SetMax),max);
            else
                progressBar1.Maximum = max;
        }

        public void _IncProgressBar()
        {
            if (this.InvokeRequired)
                this.Invoke(new Action(_IncProgressBar));
            else
                progressBar1.Value += 1;
        }

No comments: