In my C# windows form project my program is not able to get the text from a text box, nor set the text box. I am able to register button clicks, so it seems that the programs GUI thread is okay. 

```
private void sendButton_Click(object sender, EventArgs e)
{
    Console.WriteLine("I am being pressed");
    textBox2.Text = "Test";
    this.Refresh();
}

```

As you can see from the code when the button is pressed the output panel says "I am being pressed". However, the text box does not visually update and say "Test". 

Is there a reason why I am not able to set or get text. I have tried appending the text, but that is not my intention. 

My guess is that the form is not focused perhaps, since I have changed what form is showing. The code below is from the first form class. `lobby` is a new `Form` that I show.

```
if (correct)
{
    lobby lob = new lobby(client, this);
    this.Hide(); // this is the first form the user sees, I have hidden it. If I close this form then the application exits.
    lob.Show(); // this is the form that I show after the user logs in with right credentials. Textbox.text = "test" does not work on this for some reason.                
}

```

In the first form window I am able to use the `Text` method and retrieve/set values. 

But I cannot do the same in the second form.

--------Edit-------
This is the GUI builder for the second form.
[![GUI Buider](https://i.stack.imgur.com/1Qz7K.png)](https://i.stack.imgur.com/1Qz7K.png)
You can see the name field is called "TextBox2".

lobby.cs file

```
using System.Net.Sockets;
using System.Windows.Forms;

namespace ClientMMO
{
    public partial class lobby : Form
    {
        static int counter;
        private Socket client;
        private Form1 form1;

        public lobby()
        {
            InitializeComponent();
        }

        public lobby(Socket client)
        {
            InitializeComponent();
            this.client = client;   

        }

        public lobby(Socket client, Form1 form1) : this(client)
        {
            InitializeComponent();
            this.form1 = form1;

            textBox2.Text = "Test";

        }

    }
}

```

lobby.Designer.cs

```
namespace ClientMMO
{
    partial class lobby
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.textBox2 = new System.Windows.Forms.TextBox();
            this.SuspendLayout();
            // 
            // textBox2
            // 
            this.textBox2.Location = new System.Drawing.Point(107, 90);
            this.textBox2.Name = "textBox2";
            this.textBox2.Size = new System.Drawing.Size(251, 20);
            this.textBox2.TabIndex = 0;
            // 
            // lobby
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(511, 413);
            this.Controls.Add(this.textBox2);
            this.Name = "lobby";
            this.Text = "lobby";
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.TextBox textBox2;
    }
}

```

This is the first form that the user sees. Everything works normal here, as it should. 

```
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Xml;
using System.Xml.Serialization;

namespace ClientMMO
{
    public partial class Form1 : Form
    {
        Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
        User test;
        public Form1()
        {
            InitializeComponent();
            ConnectToServer();
        }

        private void ConnectToServer()
        {
            IPAddress ipAddress = IPAddress.Loopback;
            IPEndPoint ep = new IPEndPoint(ipAddress, 1234);
            client.Connect(ep);
            Console.WriteLine("connnected");

        }

        private void button1_Click(object sender, EventArgs e)
        {
            test = new User();
            test.UserName = textBox1.Text;
            test.Password = textBox2.Text;
            client.Send(ClassToByteArray(test));
            byte[] data = new byte[1024];
            client.Receive(data);
            string returndata = System.Text.Encoding.ASCII.GetString(data);
            label1.Text = returndata;
            //Console.WriteLine(returndata);
            string b = "Logged in";

            int result = 0;
            string str1 = "Logged in";

            result = string.Compare(str1, returndata);
            if (result == 0)
            {
                button1.Visible = false;
                byte[] shit = new byte[1024];
                client.Receive(shit);
                Console.WriteLine(shit.ToString());
                string sfs = System.Text.Encoding.ASCII.GetString(shit);
                label1.Text = String.Empty;
                label1.Text = sfs;

                int port = Int32.Parse(sfs);
                client.Close();
                client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                IPAddress ipAddresse = IPAddress.Loopback;
                IPEndPoint epe = new IPEndPoint(ipAddresse, port);
                client.Connect(epe);
                Console.WriteLine("connected to another server");

                /*------------------------------------This is where I open up my new window --------------------*/

                lobby lob = new lobby(client, this);
                this.Hide(); // this is the first form the user sees, I have hidden it. If I close this form then the application exits.
                lob.Show(); // this is the form that I show after the user logs in with right credentials. Textbox.text = "test" does not work on this for some reason.

            }
            else
            {
                label1.Text = "failed";
            }

        }

        private byte[] ClassToByteArray(Object objClass)
        {
            try
            {
                MemoryStream ms = new MemoryStream();
                XmlSerializer xmlS = new XmlSerializer(typeof(User));
                XmlTextWriter xmlTW = new XmlTextWriter(ms, Encoding.UTF8);

                xmlS.Serialize(xmlTW, objClass);
                ms = (MemoryStream)xmlTW.BaseStream;

                return ms.ToArray();
            }
            catch (Exception)
            {
                throw;
            }
        }

        private Object ByteArrayToClass(byte[] buffer)
        {
            try
            {
                XmlSerializer xmlS = new XmlSerializer(typeof(User));
                MemoryStream ms = new MemoryStream(buffer);
                XmlTextWriter xmlTW = new XmlTextWriter(ms, Encoding.UTF8);

                return xmlS.Deserialize(ms);
            }
            catch (Exception)
            {
                throw;
            }
        }

    }

}

```