You would create 2 images, ImageON.png and ImageOFF.png, add them to the AdvancedHMI project resources and then in the Designer you can set one of these images as the initial BackgroundImage for the BasicButton (probably ImageOFF.png as the off state is the most common to start with). The examples below use the BasicButton3 name which you would replace with the name of your button.
Then, if you just want these images to change with every click of the button, you can add to the MainForm a code similar to this:
Private flagImage As Boolean
Private Sub BasicButton3_Click(sender As Object, e As EventArgs) Handles BasicButton3.Click
If Me.flagImage Then
Me.BasicButton3.BackgroundImage = My.Resources.Image_OFF
Me.flagImage = False
Else
Me.BasicButton3.BackgroundImage = My.Resources.Image_ON
Me.flagImage = True
End If
End Sub
If you want to set images as per the state of a certain boolean address then you can add to the MainForm a code similar to this:
Private Sub BasicButton3_Click(sender As Object, e As EventArgs) Handles BasicButton3.Click
If CBool(Me.ModbusTCPCom1.Read("00001", 1)(0)) Then
Me.BasicButton3.BackgroundImage = My.Resources.Image_ON
Else
Me.BasicButton3.BackgroundImage = My.Resources.Image_OFF
End If
End Sub
This code above is using a driver from the MainForm, in this case ModbusTCPCom1, to read that specific address.