Click here to Skip to main content
15,877,966 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello all, i have built a simple form to use as a staff rota. With txt boxes to represent the month day of each employee. Its a 3 shift system. I wish to color co-ordinate the shifts to three different colors. once a click on a text box happens i wish to change the color from one to the next color of three ... for example 6-2 shift is color red, 2-10 shift color green and 10-6 color dark blue. Its to produce a rota of staff for a coming month in advance via quick easy color coding over a click of a text box.
Has anyone any suggestions of this im new to Visual studio and self teaching myself

What I have tried:

None to Date tried only as per one single txt box i have several to change
Posted
Updated 13-Mar-17 4:47am
v2
Comments
CHill60 13-Mar-17 10:45am    
What is the problem with applying the backcolor to more than 1 textbox?

1 solution

The Solution will be a customized Control with the behaviour you want.
This could also be a Label if you want to work with fixed Text's.

For Example :
VB
Public Class ShiftLabel
    Inherits Label

    Public Sub New()
        Me.AutoSize = False
        Me.TextAlign = ContentAlignment.MiddleCenter
        Me.Invalidate()
    End Sub

    Private myCounter As Integer = 1

    Protected Overrides Sub OnClick(e As EventArgs)
        myCounter += 1
        If myCounter > 3 Then myCounter = 1
        Me.Invalidate()

        MyBase.OnClick(e)
    End Sub

    Protected Overrides Sub OnInvalidated(e As InvalidateEventArgs)
        Select Case myCounter
            Case 1
                Me.Text = "Shift 1"
                Me.BackColor = Color.Red
                Me.ForeColor = Color.Yellow
            Case 2
                Me.Text = "Shift 2"
                Me.BackColor = Color.Green
                Me.ForeColor = Color.Yellow
            Case 3
                Me.Text = "Night-Shift"
                Me.BackColor = Color.DarkBlue
                Me.ForeColor = Color.White
        End Select

        MyBase.OnInvalidated(e)
    End Sub
End Class
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900