I'm new to this site and VB, so please keep that in mind.
I have a program which basically connects to our database and updates it, but what I want is after this code:
Private Sub Button1_Click(ByVal sender As system.EventArgs) Handels Button1.Click
If Retry = 0 then
End
Else
TextBox3.Textt = ""
Button1.text = "Ok"
Button1.enabled = False
Me.refresh()
System.Threading.Thread.Sleep(500)
Me.Form1_Load(Me, e)
System.Threading.Thread.Sleep(500)
Me.Refresh()
System.Windows.Form.Application.DoEvent()
End If
End Sub
End Clas
This form/App to close (can be closed before this part as it just tells me everything went well but still if you click ok will retry) so I don't have to close it every time I run this app to update and then annoyingly stay awake as it won't let me study the code nor let me change anything until this app is closed. sometime it takes so long that i even forget i have this app running.
I can provide more info if tell me what otherwise I don't know much about VB.
You can use Me.Close() it will close the form when executed.
Or Application.Exit() you can check HERE
Related
I have an anti-virus program which I'm developing.
I've noticed that with a lot of anti-viruses, it gives you a first-time alert saying: 'Please perform a first scan', and then when you click the scan button, the 'Please perform a first scan' message goes away, and changes to 'You are protected'.
I know how to do this with a simple .Hide line of code, but how do you make it so when you next open the program, the message is still 'You are protected'.
This is my code:
Public Class Mainframe
Private Sub FlatButton1_Click_1(sender As Object, e As EventArgs) Handles FlatButton1.Click
PictureBox2.Hide()
Label2.ForeColor = Color.Green
Label2.Text = "Awesome!"
Label3.Text = "You are protected."
Label3.Location = New Point(453, 152)
FlatButton1.Hide() '22
FlatButton2.Location = New Point(453, 229) '21
PictureBox3.Show()
PictureBox3.Location = New Point(218, 115)
Label2.Location = New Point(341, 152)
End Sub
Private Sub FlatButton2_Click(sender As Object, e As EventArgs) Handles FlatButton2.Click
ScanPage.Show()
End Sub
End Class
I'm a bit of a newbie to this Stackoverflow questioning feature, so my apologies if I didn't explain it well, no excuse though. If you need any additional information, just comment below.
You should use streamwriter to write scan summary in disk and streamreader to read at window loading.
This help you to identify whether system already performed scan or not.
Otherwise option of window service also helpful in case of antivirus.
I am trying a simple code in Silk4Net using VB.Net. I have automated launching of a calculator. Before the numbers can be typed, a message box appears. I am unable to find a way to dismiss the message box automatically. I want to be able to recognize the message box and either push it to the back or dismiss it totally.
The code is as below:
<TestMethod()>
Public Sub TestMethod1()
With _desktop.Window("Calculator")
.SetActive()
generateMsg()
.PushButton("Clear").Select()
.PushButton("3").Select()
.PushButton("5").Select()
End With
End Sub
Public Sub generateMsg()
Thread.Sleep(2000)
With _desktop.Window(MsgBox("Test", MsgBoxStyle.Critical, "Test"))
For Each p As Process In Process.GetProcesses
If p.MainWindowTitle.Contains("Test") Then
p.Kill()
End If
Next
'With .Dialog("Test")
' '.PushButton("OK").Select()
'End With
' .Close()
End With
End Sub
Any help would be much appreciated. Thanks.
Updated answer
You could add a timer to the code that uses SendKeys.SendWait - like this - adapting it a little for your test environment as I'm not sure about Silk4Net tbh
Dim WithEvents timer1 As New System.Timers.Timer
timer1.Interval = 5000
timer1.Enabled = True
MsgBox("Hello. I will go bye-bye in 5 seconds.")
timer1.Enabled = False
And as a separate sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles timer1.Elapsed
SendKeys.SendWait("{ENTER}")
End Sub
I am making an server control application ( simple with some buttons to start/stop the server )
And when the user wants to close the application there will be prompted an confirm box.
Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
Dim response As Integer
response = MsgBox("Are you sure you want to stop the server", vbYesNo, "Stop Server ?")
If response = vbYes Then
Shell("cscript ""stop.vbs""", 1)
Close()
Else
e.Cancel = True
End If
End Sub
That is the code I have now.
But when I start the application and close it with the X button or with "Close Window" I will be prompted with the question until I click on no, then it will close.
It's a loop and it stops when you first click on yes then on no.
Can someone help me with solving this ?
Just remove the Close() call, since the Form is already closing. No need to do that.
I'm in the process of writing a VB app that launches at user login. The issue I see is that on Windows 7/2008 when closing the last form using both Me.Close or Application.Exit both throw the error message "did the application close properly". On WindowsXP it closes without issue.
One of the basic features of the app is that when loading it checks some values and closes the app based on those values. Even in this instance I get the "did not close properly" message on win 7/2008. What could I be doing wrong?
Private Sub Dialog1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If fName = failsafeUser Then
allowLogin = vbTrue
Process.Start(My.Settings.ExplorerPath)
'Me.Close() ' TODO Check into why Me.Close() is ending poorly on 2008 servers
Application.Exit()
End If
End Sub
try using
End
to close your app. That should work. Obviously application.Exit is the better option, but End should work.
Thanks
Paul
I have a single windows form application that is running in system tray icon.If the user press X button of the windows form a messagebox is displayed with Yes and No ( Yes ->close the form---No->keep the form running in system tray icon).
I was thinking to prevent the scenario when the user open another instance of the application when there is already an instance running so i have used this code :
If Process.GetProcessesByName(Process.GetCurrentProcess.ProcessName).Length> 1 Then
MessageBox.Show("Another instance is running", "Error Window", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation)
Application.Exit()
End If
The problem is that when i want to test this the message is displayed but after i press ok, a new messagebox appears (that one from Private Sub Form_FormClosing ).If i choose NO i will have to instance running!
I have read that Application.Exit fires the Form_FormClosing event.
Is there any possibility to cancel the triggering of the Form_FormClosing event,or am i doing something wrong?
'this is the formclosing procedure
Private Sub Form_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Try
Dim response As MsgBoxResult
response = MsgBox("Are you sure you want to exit", CType(MsgBoxStyle.Question + MsgBoxStyle.YesNo, MsgBoxStyle), "Confirm")
'If the user press Yes the application wil close
'because the application remains in taskmanager after closing i decide to kill the current process
If response = MsgBoxResult.Yes Then
Process.GetCurrentProcess().Kill()
ElseIf response = MsgBoxResult.No Then
e.Cancel = True
Me.WindowState = FormWindowState.Minimized
Me.Hide()
NotifyIcon1.Visible = True
End If
PS: I am not a programmer so please don't be to harsh with me:)
You don't need to Kill the current process or use the End Statement. If you have to use these then there is something amiss with your application.
When you want to end your application use Me.Close. This will fire the FormClosing event:
Private Sub Form1_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Select Case MessageBox.Show("Are you sure you want to exit?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
Case Windows.Forms.DialogResult.Yes
'nothing to do here the form is already closing
Case Windows.Forms.DialogResult.No
e.Cancel = True 'cancel the form closing event
'minimize to tray/hide etc here
End Select
End Sub
To stop more than one copy of your application from running use the option to Make Single Instance Application
In the situation where you are just starting your application and are testing for previous instances I have used the VB End Statement to terminate the application.
The End statement stops code execution abruptly, and does not invoke
the Dispose or Finalize method, or any other Visual Basic code. Object
references held by other programs are invalidated. If an End statement
is encountered within a Try or Catch block, control does not pass to
the corresponding Finally block.
If Process.GetProcessesByName(Process.GetCurrentProcess.ProcessName).Length> 1 Then
MessageBox.Show("Another instance is running", "Error Window", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End
End If
Private Sub main_master_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
If e.CloseReason = CloseReason.UserClosing Then
'Put you desired Code inside this!
Msgbox("Application Closing from Taskbar")
End If
End Sub
It will Close the exe from Taskbar or kill Process. If user Close the
Application from taskbar.
CloseReason.UserClosing
event will close the application if it is closed by User from
Taskber