question

SOUBHIKBISWAS-3645 avatar image
0 Votes"
SOUBHIKBISWAS-3645 asked XingyuZhao-MSFT commented

Button colour change through system time

In Vb.net I have 34 different Button that button colour have to change in red with set time (it's should continue run ,if software close also it should not off means software reopen that button colour should be red ) and duration time ...
Is it possible??
Please help me.

dotnet-visual-basic
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @SOUBHIKBISWAS-3645 ,
Do you still meet this issue? Please let me know if you need further help.

0 Votes 0 ·
XingyuZhao-MSFT avatar image
1 Vote"
XingyuZhao-MSFT answered

Hi @SOUBHIKBISWAS-3645 ,
Right click your project -> 'Properties' -> 'Resources' -> then save the set time as string.
For Example:
115731-screenshot-2021-07-19-101259.png
Finally, you can refer to the following code to set Button colour.

     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
         If Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd")) > Convert.ToDateTime(My.Resources.MyDateTime) Then
             BackgroundWorker1.RunWorkerAsync()
         End If
     End Sub
     Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
         Button1.BackColor = Color.Red
     End Sub

Hope it could be helpful.

Best Regards,
Xingyu Zhao


If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

karenpayneoregon avatar image
0 Votes"
karenpayneoregon answered karenpayneoregon edited

Hello,

Full source

  • Create a setting under project properties for storing the date (or store it in a text file), the code below uses MySettings.

  • Use code below which checks today date against the date under MySettings. If met set one button's back color and then set the others via a list.

Code

     Public Class Form1
         Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles Me.Shown
             CheckDateCondition()
         End Sub
        
         Private Sub CheckDateCondition()
             If Now >= My.Settings.DateSetting Then
        
                 Dim buttonList = Controls.
                         OfType(Of Button).
                         Where(Function(but) but.Name <> "Button1").
                         ToList()
        
                 Button1.BackColor = Color.Red
        
                 For Each button As Button In buttonList
        
                     button.DataBindings.Add(
                         "BackColor",
                         Button1,
                         "BackColor")
        
                 Next
             End If
         End Sub
     End Class



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.