Hi guys, im making a chat app in C#
I can get it to show time and text but the code im using shows PC username not login username of app
Could someone please help me with the correct bit to put it
Thanks in Advance

            if (textBoxSend.Text != "")
            {
                richTextBoxChat.Text += DateTime.Now.ToString("hh:mm:ss:tt") + " :  " + System.Environment.GetEnvironmentVariable("username") + textBoxSend.Text + Environment.NewLine;
                textBoxSend.Text = "";

            }

The chat username would rarely if ever exist as a Windows environment variable. Given so little of your chat app's code to read, Carnac the Magnificent might say the answer is in the rest of the code.

Sorry I thought the main part of interest was the + Environment.GetEnvironmentVariable("username") +

private void btnSend_Click(object sender, EventArgs e)
        {
            DB db = new DB();
            String chat = textBoxSend.Text;

            DataTable table = new DataTable();
            MySqlDataAdapter adapter = new MySqlDataAdapter();
            MySqlCommand command = new MySqlCommand("SELECT * FROM `chat` WHERE `chat` = @chat", db.getConnection());

            command.Parameters.Add("@chat", MySqlDbType.VarChar).Value = chat;

            adapter.SelectCommand = command;
            adapter.Fill(table);

            if (textBoxSend.Text != "")
            {
                richTextBoxChat.Text += DateTime.Now.ToString("hh:mm:ss:tt") + " :  " + Environment.GetEnvironmentVariable("username") + " :" + textBoxSend.Text + Environment.NewLine;
                textBoxSend.Text = "";
            }
        }

At this point I will guess this is what I call "found code." That is, you are not the author and need others to read and alter it for you.

Again I don't see a value that could be the username for the chat there. Maybe this found code was designed to only chat using the username from the Windows log in account but that would be me guessing.

Where did you get this code from?
Can you point us to it so all can dig around?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.