First MessageBox not showing on FormLoad Event - vb.net

In my application I want one of my Windows Form to show a MessageBox if something is true but I am not able to get it but I can solve that by throwing some other event before that MessageBox, I mean it works if some other action is done before that
My Code for NotWorking MessageBox:
Private Sub MainInterface_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
If My.Settings.RowName <> "" Then
If My.Settings.LastModifiedCheck <> SOMETHING Then
MsgBox("Hello :)")
End If
End If
End Sub
My Code for Working MessageBox:
Private Sub MainInterface_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
If My.Settings.RowName <> "" Then
If My.Settings.LastModifiedCheck <> SOMETHING Then
MsgBox("Hello :)")
MsgBox("Hello2 :)")
End If
End If
End Sub
In this code what it will do is, it will show the second MsgBox, i.e, "Hello 2 :)" but will still ignore the first MsgBox which was just "Hello :)"
Edit:
If I add the style MsgBoxStyle.Critical to the MessageBox Style I can hear the Critical Sound but still don't get the MessageBox. No idea what's going on. It seems very bad BTW, I mean this looks impossible! how can a MsgBox closes itself automatically.

Okay, So I solved my problem with this partial solution but still wonder what was the problem...
Instead of adding the MsgBox event inside the Form.Load Event I inserted the even inside Form.Shown event
Example
Private Sub MainInterface_Shown(sender As Object, e As EventArgs) Handles Me.Shown
If My.Settings.RowName <> "" Then
If My.Settings.LastModifiedCheck <> SOMETHING Then
MsgBox("Hello :)")
End If
End If
End Sub
And it worked fine!

Related

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

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
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

Expression is not a method

Hello Coders Im trying to code a Anti virus and the following problem was here!
Im trying to add MsgBoxStyle.YesNo and will the problem in this...
So im trying to add a Question for delete file or no with MsgBox.
My code:
Imports System.IO
Public Class Form1
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Label1_Click(sender As System.Object, e As System.EventArgs)
End Sub
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
If My.Settings.ifTmpR = True Then
For Each aF In Directory.GetFiles(My.Computer.FileSystem.SpecialDirectories.Temp)
Try
MsgBoxStyle.YesNo()
MsgBox("Biztosan törli: " + aF)
IO.File.Delete(aF)
MsgBox("Temp kiürítése: " + aF)
MsgBox(aF + "kitötrölve")
Catch ex As Exception
End Try
Next
End If
If My.Settings.ifTmpR = False Then
Try
MsgBox("Kérlek kapcsold be a TEMP Queryt!")
Catch ex As Exception
End Try
End If
End Sub
Private Sub RadioButton1_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles RadioButton1.CheckedChanged
If RadioButton1.Checked = True Then
My.Settings.ifTmpR = True
End If
End Sub
Private Sub RadioButton2_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles RadioButton2.CheckedChanged
If RadioButton2.Checked = False Then
My.Settings.ifTmpR = False
End If
End Sub
End Class
And what the problem?
Help?
So you're coding an Anti-Virus application but you seem to have no basic knowledge about how to use methods and parameters.
You are supposed to include MsgBoxStyle.YesNo as one of the parameters to the MsgBox() method. You cannot call it like you do since it's simply an Integer value.
As Steve suggested you should use MessageBox.Show() instead, due to that MsgBox only exists for backwards compability.
The first parameter is the message you want it to show, and the second parameter is what title the window should have. They're just plain strings.
The third parameter however is the one you pass to tell the method what buttons to include in the MessageBox, and it should be passed like this:
MessageBox.Show("I am a message", "I am a title", MessageBoxButtons.YesNo)
This will show a message box with the buttons "Yes" and "No" inside it.
Now to get use out of this you should put your MessageBox in an If-statement, otherwise the application won't care if you press either Yes or No.
If MessageBox.Show("Are you sure you want to delete this file?", "Confirmation", MessageBoxButtons.YesNo) = DialogResult.Yes Then
'Delete code here.
End If
There. Now I suggest that you would have started with something like a "Hello World"-application instead of an Anti-Virus application, as Anti-Virus is pretty much harder than just showing a simple MessageBox.

Stop form from closing conditionally

My problem is that I don't know a suitable command to stop my code from running. If I use a return statement, like below, the code in the subroutine btnClose will keep running causing the program to close on an error. The form must not close if an error on saving occurs.
Private Sub Save_Customer()
If txtName.text = "" then
msgbox("Error")
return
End If
End sub
Private Sub btnClose_Click(sender As System.Object, e As System.EventArgs) Handles btnClose.Click
save_Customer()
Me.Close()
End Sub
Change the Sub to a Function, then evaluate the return:
Private Function Save_Customer() As Boolean
If txtName.text = "" then
msgbox("Error")
return False
Else
Return True
End If
End sub
Private Sub btnClose_Click(sender As System.Object,
e As System.EventArgs) Handles btnClose.Click
' evaluate the return:
If save_Customer() Then
Me.Close()
End IF
End Sub
You should better intercept Closing event, and Cancel closing via e.Cancel = True. Doing it otherwise would result in too much plumbing. (You can close the form not only via btnClose, right)? Also ALT+F4, Mouse click on X button etc. Be careful though, not to leave your user in a deadlock, where they cannot close your form, and have to fall back to using task manager.
That is probably not the best way around your problem, but you could solve it like this:
Private Function Save_Customer()
If txtName.Text = "" Then
MsgBox("Error")
Return False
Else
Return True
End If
End sub
Private Sub btnClose_Click(sender As System.Object, e As System.EventArgs) Handles btnClose.Click
If Save_Customer() = False Then
Exit Sub
Else
Me.Close()
End if
End Sub
End Class

Click Button Event in VB that displays a message about user input

I have a really quick and simple question, I’m learning programming in C# and VB and I need to create a GUI application in Windows Form with Visual Studio. This GUI will prompt the user to enter in an integer. I believe I have this part alright but then I need to have the user click a button that will convert the user's entry to an integer and display a message indicating whether the user was successful. I think I even have the conversion done correctly but I am having a problem displaying that message if the user was successful. Basically I need to know how to function the click method in VB that will allow this message to appear. Any help with this would be greatly appreciated. The following code is what I have already written for this project:
Public Class Form1
Private Sub EvaluateInput()
Dim InputValue As String
InputValue = ValueTextBox.Text
If IsNumeric(InputValue) Then
MessageBox.Show(InputValue & " is a number.")
Else
MessageBox.Show(InputValue & " is not a number.")
End If
End Sub
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click 'Continue Button
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'Exit Button
Dim button As DialogResult
button = MessageBox.Show _
("Are you sure you want to exit this application?", _
"Message", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1)
If button = Windows.Forms.DialogResult.Yes Then
Me.Close()
Else
'Do Nothing
End If
End Sub
End Class
If I understand your question correctly, then you would need a simply change:
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) _
Handles Button2.Click 'Continue Button
EvaluateInput()
End Sub
When you press Button2, it will call the EvaluateInput sub and display a message accordingly.