Ver Mensaje Individual
  #7 (permalink)  
Antiguo 12/12/2009, 11:12
klaudio83
 
Fecha de Ingreso: octubre-2009
Mensajes: 70
Antigüedad: 15 años, 4 meses
Puntos: 0
Respuesta: Cerrar formulario y confirmar cierre al presiona el boton X del form

Ups!, disculpen, me equivoque no funciona de la manera en que habia puesto en el post anterior.
Intente de otra forma y tampoco funciono,

Código vb.net:
Ver original
  1. Private Sub nueva_factura_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
  2.         Dim dlgRes As DialogResult
  3.         dlgRes = MessageBox.Show("Desea Cerrar y Guardar los Cambios Efectuados?", "Confirmar", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
  4.  
  5.         If e.CloseReason = CloseReason.UserClosing Then
  6.             If dlgRes = Windows.Forms.DialogResult.Yes Then
  7.                 Dim valor As Boolean
  8.                 valor = btnGuardar()
  9.                 If valor = True Then
  10.                     Me.Dispose()
  11.                 End If
  12.                 If valor = False Then
  13.                     e.Cancel = True
  14.                 End If
  15.             End If
  16.  
  17.             If dlgRes = Windows.Forms.DialogResult.No Then
  18.                 Me.Dispose()
  19.             End If
  20.         End If
  21.  
  22.     End Sub

y el boton guardar lo hago de esta manera
Código vb.net:
Ver original
  1. Private Sub guardar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles guardar.Click
  2.         If String.IsNullOrEmpty(txCodigoCli.Text) Then
  3.             ep.SetError(txCodigoCli, "Ingrese un Cliente")
  4.             If ListView1.Items.Count - 1 < 0 Then
  5.                 MessageBox.Show("Ingrese una Linea de Detalle ", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  6.                 Exit Sub
  7.             End If
  8.             Exit Sub
  9.         End If
  10.         ep.Clear()
  11.  
  12.         If ListView1.Items.Count - 1 < 0 Then
  13.             MessageBox.Show("Ingrese una Linea de Detalle ", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  14.             If String.IsNullOrEmpty(txCodigoCli.Text) Then
  15.                 ep.SetError(txCodigoCli, "Ingrese un Cliente")
  16.                 Exit Sub
  17.             End If
  18.             Exit Sub
  19.         End If
  20.         ep.Clear()
  21.  
  22.         Dim iva As String = obtenerIVA().ToString
  23.         iva = iva * 100
  24.         total = CalculaTotal()
  25.         Dim IdFactura As Integer = ingresar_factura(txCodigoCli.Text, txFecha.Text, total, txtOrden.Text, txtObs.Text, iva)
  26.  
  27.         Dim fila As Integer
  28.         For fila = 0 To ListView1.Items.Count - 1
  29.             Dim codProd As String = ListView1.Items(fila).SubItems(0).Text
  30.             Dim cantidad As String = ListView1.Items(fila).SubItems(3).Text
  31.             Dim precio As String = ListView1.Items(fila).SubItems(4).Text
  32.             Dim obs As String = ListView1.Items(fila).SubItems(6).Text
  33.             ingresar_detalle(codProd, IdFactura.ToString, precio, cantidad, obs)
  34.         Next
  35.         Me.Dispose()
  36.     End Sub

Espero me puedan ayudar y disculpen que moleste tanto.
Gracias