Text box value fore color

jmasgalas

Member
Joined
Apr 21, 2007
Messages
15
Programming Experience
Beginner
I have a textbox that is set to display the computer username. I created this by simply doing:
txtUsername.Text = Environment.GetEnvironmentVariable("USERNAME")

My problem is that I want to change the text to red. I tried setting this in properties but it still displays as black. Can someone help me out?
 
to do it in code simply change the ForeColor property to Color.Red, I would do it in the FormLoad event
txtUsername.ForeColor = Color.Red
 
I tried that but I put the code after the environment variable code. maybe it will work if I put it before? I'll let you know how it goes.
 
The above did not work. Here is my entire code on this project:
VB.NET:
Public Class frmSSOUserWarning
    'Declare the starttime variable as a date
    Private starttime As Date

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Set the start time to Date.now value
        starttime = Date.Now
        'Set the Username textbox to the environment variable of the usrname
        txtUsername.Text = Environment.GetEnvironmentVariable("USERNAME")
    End Sub

    Private Sub Form1_Move(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Move
        'Prevents form from being moved
        MyBase.Location = New System.Drawing.Point(30, 30)
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        'Declare the countdown variable
        Dim countdown As New TimeSpan(0, 3, 0)
        'Set the countdown to start from 3 minutes and go to 0.
        'Displays the countdown in the countdown text box.
        'When it hits zero it runs tsdiscon.exe and closes the program.
        countdown = countdown.Subtract(Date.Now.Subtract(starttime))
        txtCountdown.Text = String.Format("{0}:{1:00}", countdown.Minutes, countdown.Seconds)
        If countdown.TotalSeconds <= 0 Then
            Timer1.Enabled = False
            Process.Start("C:\windows\system32\tsdiscon.exe")
            Close()
        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnContinue.Click
        Close()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisconnect.Click
        Process.Start("C:\windows\system32\tsdiscon.exe")
        Close()
    End Sub

    Private Sub txtUsername_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtUsername.TextChanged

    End Sub
End Class
 
Last edited by a moderator:
IN the above I want the displayed USERNAME in txtUsername.text to display in red font. I tried adding txtUsername.ForeColor = Color.Red under Private Sub Form1_Load but it did not work. Any ideas?
 
This works for me:
VB.NET:
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Set the start time to Date.now value
        starttime = Date.Now
        'Set the Username textbox to the environment variable of the usrname
        txtUsername.Text = Environment.GetEnvironmentVariable("USERNAME")
        txtUsername.ForeColor = Color.Red
    End Sub
 
Not working here. Font is still black. Now I can set it to bold and it works. Could something else be preventing the font color?
 
Everything else is set to default. I can change the label fonts fine but this dang text box font will not change. I am at home now but can I contact you through e-mail about this tomorrow from work?
 
I got it working. Not sure why but I put a border back on the box and the font changed. I then changed it back to none and it works!
 
Back
Top