Problems adding a picture in checkbox in checkedchanged event - vb.net

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

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

Related

VB.Net BalloonTipText appears as a black rectangle

I have a strange problem, I have created a test form FrmTest. Added a NotifyIcon and added the code shown:
Public Class FrmTest
Private Sub FrmTest_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Sub FormTest_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Click
Call SetBalloonTip()
NotifyIcon1.Visible = True
NotifyIcon1.ShowBalloonTip(30000)
End Sub
Private Sub SetBalloonTip()
NotifyIcon1.Icon = SystemIcons.Exclamation
NotifyIcon1.BalloonTipTitle = "Balloon Tip Title"
NotifyIcon1.BalloonTipText = "Balloon Tip Text."
NotifyIcon1.BalloonTipIcon = ToolTipIcon.Error
End Sub
End Class
When I click to make the balloon appear I get this:
I must be doing something obviously wrong but I am stumped!
There is nothing to say you did well...
That is what a balloon Tip looks like on Windows 10. Best of luck.

How to do a 'Button.Clicked' tag, but for Bunifu?

I was wondering what the code is to if a button is selected, then say it will send the enter key. This make no sense, I know, and I'm sorry, but my code might help.
Private Sub BunifuCheckbox1_OnChange(sender As Object, e As EventArgs) Handles BunifuCheckbox1.OnChange
If BunifuFlatButton1.clicked() And BunifuCheckbox1.Checked = True Then
SendKeys.Send("{Enter}")
End If
End Sub
So when you look at 'BunifuFlatButton1.clicked' is there a tag for that?
Rather than try to send the string when you change the checkbox, delete that sub and use this. This way, you can change the checkbox and then click the button
Private Sub BunifuFlatButton1_Click(sender As Object, e As EventArgs) Handles BunifuFlatButton1.Click
If BunifuCheckbox1.Checked = True Then
SendKeys.Send("{Enter}")
End If
End Sub

VB.NET Create a to a form attached Preview window

I want to create a little window which gets visible when I press a button and is attached to the main Form (like shwon below). I want to use this window to show preview of Images (I gonna have a Listbox and depending on which entry is selected, a picture is shown) How can I do this? And how can I be sure that the window will always be attached to the main Form (not depending on resolution). I tried to do it with a second form, but I can't fix it in the correct position.
regards
Assuming your preview form class is frmPreview and you open it this way:
Private mPreviewForm As frmPreview
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
mPreviewForm = New frmPreview
mPreviewForm.Show()
AttachPreviewForm()
End Sub
Then you must reposition it every time the main form is changing size or location:
Private Sub AttachPreviewForm()
If mPreviewForm IsNot Nothing Then
mPreviewForm.AttachForm(Me)
End If
End Sub
Private Sub Form1_SizeChanged(sender As Object, e As EventArgs) Handles Me.SizeChanged
AttachPreviewForm()
End Sub
Private Sub Form1_LocationChanged(sender As Object, e As EventArgs) Handles Me.LocationChanged
AttachPreviewForm()
End Sub
And in the frmPreview:
Public Sub AttachForm(parent As Form)
Location = New Point(parent.Left + parent.Width, parent.Top)
Size = New Size(200, parent.Height)
End Sub

Changing button name if file exists?

I'm working on a custom GUI, my last step is for the button to change automatically check if the file exists or not on startup. The method below is my download/open button. Any help is appreciated!
Private Sub Button7_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button7.Click
If Dir("DownloadedFile.zip") <> "" Then
Process.Start("DownloadedFile.zip")
Else
WC.DownloadFileAsync(New Uri("http://download852.mediafire.com/3a688rz1a6ig/dk71cs34ihs3v6x/Devil+went+down+to+georgia.rar"), "DownloadedFile.zip")
MsgBox("Starting Download")
End If
End Sub
A subroutine is a seperate method that does not return a value. I would take the If statement out of your click eventhandler and put it in its own method as I stated like this.
Private Sub CheckForFile()
If Dir("DownloadedFile.zip") <> "" Then
Process.Start("DownloadedFile.zip")
Else
WC.DownloadFileAsync(New Uri("http://download852.mediafire.com/3a688rz1a6ig/dk71cs34ihs3v6x/Devil+went+down+to+georgia.rar"), "DownloadedFile.zip")
MsgBox("Starting Download")
End If
End Sub
Call it from your button like this.
Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
CheckForFile()
End Sub
Then handle the Shown Event and call it from there. It will run as soon as the initial form is shown
Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles Me.Shown
CheckForFile()
End Sub
Responding to your comment You need to use the WebClient DownloadFileCompleted Event and the WebClient DownloadProgressChanged Event

Drop onto FlowLayoutPanel

Hi guys Hope all is well
I am wondering(struggling) the following:
I have 5 flowLayoutPanels and 5 PictureBoxes i want to be able to move anyone of the picture boxes over anyone the FLP at run time and have the layout panel add it to FLP.controls.Add()....
I've been at it for Hours and now ill swallow my pride -
I have done the following To get it working, but here i have to manually specify which PixBox intersects with which FLP and i dont want 25 if statements
Private Sub cpbPic1_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles cpbPic1.MouseUp
If (flpDock1.HasChildren = False) Then 'Test to see if panel is filled
If CBool(CustomPictureBox.IntersectingObjects(cpbPic1, flpDock1)) Then
flpDock1.Controls.Add(cpbPic1) 'Add Pic to Panel
End If
End Sub
cpb: CustomPictureBox
you could always do this:
Private Sub cpbPic1_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles cpbPic1.MouseUp, cpbPic2.MouseUp, cpbPic3.MouseUp,cpbPic4.MouseUp,cpbPic5.MouseUp
If Not flpDock1.HasChildren Then 'Test to see if panel is filled
If CBool(CustomPictureBox.IntersectingObjects(TryCast(sender,CustomPictureBox), flpDock1)) Then
flpDock1.Controls.Add(TryCast(sender,CustomPictureBox)) 'Add Pic to Panel
End If
End Sub
This will reduce the amount of code you'll have to write significantly, you can further reduce this amount if you think about how to utilize the fact that the event handler passes the Object which raises the flag, like I did here.
Also you can use arbitrary big amount (i think) of objects in a handler as long as they raise the same event
well this can be a work around for what you want to do.
you also have to enable allowdrop to the flowpanels
Private Function FindControl(ByVal ControlName As String, ByVal CurrentControl As Control) As Control
' get the control you need
Dim ctr As Control
For Each ctr In CurrentControl.Controls
If ctr.Name = ControlName Then
Return ctr
Else
ctr = FindControl(ControlName, ctr)
If Not ctr Is Nothing Then
Return ctr
End If
End If
Next ctr
End Function
Private Sub me_DragEnter(sender As Object, e As DragEventArgs) Handles FLP1.DragEnter,FLP2.DragEnter,FLP3.DragEnter
' call the copy effect
If (e.Data.GetDataPresent(DataFormats.Text)) Then
e.Effect = DragDropEffects.Copy
End If
End Sub
Private Sub me_DragDrop(sender As Object, e As DragEventArgs) Handles FLP1.DragDrop,FLP2.DragDrop,FLP3.DragDrop
' get the FLp you're gonna drop the control onto
Dim c As control =FindControl(e.Data.GetData(DataFormats.Text), me)
sender.Controls.Add(c)
end sub
Private Sub Pictureboxs_MouseDown(sender As Object, e As MouseEventArgs) Handles Label1.MouseDown, PB.MouseDown
sender.DoDragDrop(sender.Name, DragDropEffects.Copy)
End Sub
hope that this helps you :) (sorry for my bad english)