Question Form loses focus

AussieBoy

Well-known member
Joined
Sep 7, 2020
Messages
78
Programming Experience
Beginner
Hi Gents, my form loses focus.
It was working ok.
Thanks,

C#:
namespace TestClient
{
    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());
            
        }
    }
}

C#:
public Form1()
        {
            InitializeComponent();
            Cursor.Current = Cursors.WaitCursor;
            Cursor.Current = Cursors.Default;
            //GetValue();
            InitTimer();
        }

C#:
this.ClientSize = new System.Drawing.Size(993, 388);
            this.Controls.Add(this.label5);
            this.Controls.Add(this.txtBoxTaskComplete);
            this.Controls.Add(this.label4);
            this.Controls.Add(this.textBoxTaskReq);
            this.Controls.Add(this.txtBoxResponceJson);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.txtBoxPost);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.txtBoxResponse);
            this.Name = "Form1";
            this.Text = "Test Form";
            this.ResumeLayout(false);
            this.PerformLayout();
 
Moved to winforms.

Explain your problem. We aren't mind readers.

Lost focus how? What happens? When does it happen? How does it happen? Describe your problem in detail or you might find someone will close your topic for lack of detail.

We shouldn't need to ask you to clarify or be more elaborate.

Conesole app or winforms?
 
Does your timer event handler do anything like change the focus. Because with the code in OP, I don't see anything there that would would change the focus.
 
Hi, the form loads up, then the title and close cross in top right corner go greyed out .
The close cross is then non functional.
Thanks,
 
Comment out your call to InitTimer(). Does it behave the same way?
 
VS suggested I changed to Timer1_Tick, but still no change.
Thanks,

C#:
public Form1()
        {
            InitializeComponent();
            Cursor.Current = Cursors.WaitCursor;
            Cursor.Current = Cursors.Default;
            //GetValue();
            InitTimer();
        }
        private Timer timer1;
        public void InitTimer()
        {
            timer1 = new Timer();
            timer1.Tick += new EventHandler(Timer1_Tick);
            timer1.Interval = 5000; // in miliseconds
            timer1.Start();
        }
        private void Timer1_Tick(object sender, EventArgs e)
        {
            GetValue();
            //InitializeComponent();
        }
 
C#:
this.ClientSize = new System.Drawing.Size(993, 388);
            this.Controls.Add(this.label5);
            this.Controls.Add(this.txtBoxTaskComplete);
            this.Controls.Add(this.label4);
            this.Controls.Add(this.textBoxTaskReq);
            this.Controls.Add(this.txtBoxResponceJson);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.txtBoxPost);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.txtBoxResponse);
            this.Name = "Form1";
            this.Text = "Form1";
            this.ResumeLayout(false);
            this.PerformLayout();
 
Hi, sorry quite hard to understand.

Are you saying this way round?

this.PerformLayout();
this.ResumeLayout(false);

Thanks,
 
Did you read the direct link I gave you?
While this won't resolve your original issue. You should make sure your calls are in the right positions syntactically.
And since you didn't bother providing the code I asked for, you will need to resolve this one yourself.
 
Back
Top Bottom