victoradv victoradv - 6 months ago 32
Vb.net Question

Problems adding a picture in checkbox in checkedchanged event

Good morning everyone.

I´m trying to put an image in a checkbox when its status changes (checkedchanged event) and then, make a screenshot with this checkbox changed status, but, when event is fired, and screenshot is done, picture does not appear before next code executes.
I´m wondering if is there any way to make it like vb after update event.
Does anyone know how can I make it?
Thanks!!

My code:

Private Sub CheckBox_accept_terms_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox_accept_terms.CheckedChanged

Try
If CheckBox_accept_terms.Checked Then

CheckBox_accept_terms.Image = My.Resources.cancelar

If moveTmpPic_finalPic() Then
If agreement_screenshot() Then
If generate_xml() Then
If generate_zip() Then
send_email_agreement = False
Common_functions.savedCapture = New Saved_capture_form
Common_functions.savedCapture.Show()
Me.Close()
End If
End If
End If
End If
End If

Catch

End Try

End Sub


I also tried:

Private Sub CheckBox_accept_terms_BackgroundImageChanged(sender As Object, e As EventArgs) Handles CheckBox_accept_terms.BackgroundImageChanged

Try
If CheckBox_accept_terms.Checked Then

If moveTmpPic_finalPic() Then
If agreement_screenshot() Then
If generate_xml() Then
If generate_zip() Then
send_email_agreement = False
Common_functions.savedCapture = New Saved_capture_form
Common_functions.savedCapture.Show()
Me.Close()
End If
End If
End If
End If
End If

Catch

End Try

End Sub

Private Sub CheckBox_accept_terms_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox_accept_terms.CheckedChanged

CheckBox_accept_terms.BackgroundImage = My.Resources.cancelar

End Sub

Answer

You can add an Update() call, or a Refresh() call, to see if that helps.

Try:

Private Sub CheckBox1_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles CheckBox1.CheckedChanged
    CheckBox1.BackgroundImage = My.Resources.garbage

    CheckBox1.Update()
    'or use refresh
    CheckBox1.Refresh()
End Sub

Update makes the control "update", and should force show your image.

If your problem is that the image is not displaying properly, it may be the layout of your background image. Stretch will make the image fit into the size of your control (rather than stay full-size).

        CheckBox1.BackgroundImageLayout = ImageLayout.Stretch