AdvancedHMI Software
General Category => Support Questions => Topic started by: MrPike on January 26, 2016, 11:20:19 PM
-
How can I access the Back Ground image of a button for control purposes. such as
If Button1.BackGround image=xxxx Then
I want to use the image in the same manner as the text to create a single button for two operations. ie..Start/Stop. Thanks
-
Probably the easiest way is to add your images to the resources like this:
- Right click the AdvancedHMI project in Solution Explorer
- Select Properties
- Select the Resources tab
- Add Resource->Add Existing File
- Browse to your images
Now that your images are in the Resources, you can add them to your button either with the Properties Window or via code:
BasicButton1.BackgroundImage = My.Resources.AdvancedHMILogoBR
The you can check which image is currently on the button like this:
If BasicButton1.BackgroundImage Is My.Resources.AdvancedHMILogoBR Then
End If
-
This doesn't seem to let me change the Back Ground Image at run time. My images are in my resources. I was hoping to change this property on the button click.
-
It turns out a little more complicated than I thought. I created a simple image comparison function. I made a demo by adding a regular Button to the form and making it switch between 2 images. This is the code:
Private Sub Button1_Click_2(sender As Object, e As EventArgs) Handles Button1.Click
If CompareImages(Button1.BackgroundImage, My.Resources.AdvancedHMILogoBR) Then
Button1.BackgroundImage = My.Resources.RoundMeterNeedle
Else
Button1.BackgroundImage = My.Resources.AdvancedHMILogoBR
End If
End Sub
Private Function CompareImages(ByRef Image1 As Bitmap, ByRef image2 As Bitmap) As Boolean
If Image1 Is Nothing AndAlso image2 IsNot Nothing Then
Return False
End If
If image2 Is Nothing AndAlso Image1 IsNot Nothing Then
Return False
End If
If Image1.Size.Width = image2.Size.Width AndAlso Image1.Size.Height = image2.Size.Height Then
If Image1.GetPixel(0, 0).A = image2.GetPixel(0, 0).A And Image1.GetPixel(0, 0).R = image2.GetPixel(0, 0).R And
Image1.GetPixel(0, 0).G = image2.GetPixel(0, 0).G And Image1.GetPixel(0, 0).B = image2.GetPixel(0, 0).B Then
Return True
Else
Return False
End If
Else
Return False
End If
End Function
-
Thanks, Maybe I will just use two buttons and alternate visibility :)