Vsbabu

Here I am working with windows forms and i have written a code in windows form activation event like shown in below.

Private Sub frmSelectEmp_Activated(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Activated

Dim IntResponse As Short

If lstEmp.Items.Count = 0 Then

IntResponse = MsgBox("No Emps, list will close")

Me.Close()

End If

End Sub

Here when I run this form iam getting this form and it is giving the messagebox and when i click Ok button on that messagebox everytime pointer is going to the Form activation event so that it is always giving the messagebox . Here my intention is when i click on the OK button on the Messagebox i need to close that dialog window( frmSelectEmp). please Check this code and give the solution.

Thanks'

Sudhakar.V



Re: Windows Forms General Working with windows forms activation event?

wjousts

Vsbabu wrote:

Here I am working with windows forms and i have written a code in windows form activation event like shown in below.

Private Sub frmSelectEmp_Activated(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Activated

Dim IntResponse As Short

If lstEmp.Items.Count = 0 Then

IntResponse = MsgBox("No Emps, list will close")

Me.Close()

End If

End Sub

Here when I run this form iam getting this form and it is giving the messagebox and when i click Ok button on that messagebox everytime pointer is going to the Form activation event so that it is always giving the messagebox . Here my intention is when i click on the OK button on the Messagebox i need to close that dialog window( frmSelectEmp). please Check this code and give the solution.

Thanks'

Sudhakar.V

For a start, if you want to close frmSelectEmp then you'll need frmSelectEmp.Close(). Me.Close() will close the form that contains this method. If that is frmSelectEmp, then you should override the base method instead of using an event.





Re: Windows Forms General Working with windows forms activation event?

nobugz

Sure, closing the MsgBox will reactive the form again. Don't use Activated, use Load or Shown. Better yet, good UI design would disable the button or menu item that shows the form.