Portal    Foro    Buscar    FAQ    Registrarse    Conectarse


Publicar nuevo tema  Responder al tema 
Página 1 de 1
 
 
Detectar Modificacion Al Pegar Texto En Textarea
Autor Mensaje
Responder citando   Descargar mensaje  
Mensaje Detectar Modificacion Al Pegar Texto En Textarea 
 
buenas,

tengo un problema con Notas, y es que no se como detectar cuando el usuario usa el botón derecho y pone pegar y así poner la variable modificado a true.
intente contando los caracteres del textarea pero no encontré la solución.

alguna sugerencia?
 




===================
Software libre, programación libre, vida libre es la Public function Libertad()as Invendible
Proyectos: VisorRV1960,Taller2015,Tanteador
https://sourceforge.net/u/v3ctor-full/profile/
Blog: http://novatocodegambas.blogspot.com.uy/
 
v3ctor - Ver perfil del usuarioEnviar mensaje privadoVisitar sitio web del usuario 
Volver arribaPágina inferior
Responder citando   Descargar mensaje  
Mensaje Re: Detectar Modificacion Al Pegar Texto En Textarea 
 
v3ctor escribió: [Ver mensaje]
buenas,

tengo un problema con Notas, y es que no se como detectar cuando el usuario usa el botón derecho y pone pegar y así poner la variable modificado a true.
intente contando los caracteres del textarea pero no encontré la solución.

alguna sugerencia?


Puedes hacerlo con el evento Change:
Public Sub TA1_Change()
  
  TB1.Text = "He cambiado"
  
End
 


TA1 es el TextArea y TB1 un TextBox. Cuando pegas algo en TA1 salta el evento Change.
Saludos
 



 
frajanic - Ver perfil del usuarioEnviar mensaje privado 
Volver arribaPágina inferior
Responder citando   Descargar mensaje  
Mensaje Re: Detectar Modificacion Al Pegar Texto En Textarea 
 
bueno quedo soluciónado pero tuve que hacer algo extraño, pues al cargar el formulario se producen un evento change

con esto:

Public Sub Form_Open()

  Me.Title = "Notas"
  Me.Center
  LabVersion.Text = FMain.NumVersion
  
  RutaNotas = FMain.TemaEstudio &/ "Notas.txt"
  If Not Exist(RutaNotas) Then
    File.Save(RutaNotas, "")
  Else
    TextArea1.Text = File.Load(RutaNotas)  <------ esto lanza un evento change
  Endif

End
 



lo solucione con esto:

Private Cargado As Boolean = True


Public Sub TextArea1_Change()
 
 If Cargado = True Then
   Cargado = False
 Else
   Modificado = True
   HayModificacion(Modificado)
 Endif
 
End

Public Sub HayModificacion(si As Boolean)
  
  If si = True Then
    btnGuardar.Enabled = True
  Else
    btnGuardar.Enabled = False
  Endif
  
End


es medio una chanchada pero anda, no se me ahogue con un vaso de agua jajajaj
 




===================
Software libre, programación libre, vida libre es la Public function Libertad()as Invendible
Proyectos: VisorRV1960,Taller2015,Tanteador
https://sourceforge.net/u/v3ctor-full/profile/
Blog: http://novatocodegambas.blogspot.com.uy/
 
v3ctor - Ver perfil del usuarioEnviar mensaje privadoVisitar sitio web del usuario 
Volver arribaPágina inferior
Responder citando   Descargar mensaje  
Mensaje Re: Detectar Modificacion Al Pegar Texto En Textarea 
 
Victor:

Yo lo he hecho de otra manera, usando variables y un control timer1... pero es mejor método el dice frajanic usando el evento _change.


Os dejo el código:
' gambas class file

Private contenido As String
Private contenidoAntiguo As String
Private banderaGuardado As Boolean

Public Sub _new()

End

Public Sub Form_Open()

  Me.center
  Timer1.Delay = 2000 '5 segundos
  Timer1.Start
  contenido = TextArea1.text
  contenidoAntiguo = contenido
  ToolButtonguardar.enabled = False

End

Public Sub Timer1_Timer()

  If contenidoAntiguo <> "" Then
    'que no este vacio

    If contenidoAntiguo <> TextArea1.text Then
      Label1.text = "El texto ha sido modificado"
      ToolButtonguardar.enabled = True
    Endif
  Endif

End

Public Sub ToolButtonguardar_Click()

  banderaGuardado = True
  ToolButtonguardar.Enabled = False
  Label1.text = ""
  contenidoAntiguo = TextArea1.text

  'aqui instrucciones de guardar el archivo
  Message.Info("Texto guardado en el disco")

End
 


modificadoTexto-0.0.1.tar.gz
Descripción:  
Descargar
Nombre del archivo: modificadoTexto-0.0.1.tar.gz
Tamaño: 5 KB
Descargado: 47 veces
modificadoTexto-0.0.1.tar.gz
Descripción:  
Descargar
Nombre del archivo: modificadoTexto-0.0.1.tar.gz
Tamaño: 5 KB
Descargado: 47 veces
modificadoTexto-0.0.1.tar.gz
Descripción:  
Descargar
Nombre del archivo: modificadoTexto-0.0.1.tar.gz
Tamaño: 5 KB
Descargado: 47 veces

 




===================
Blog personal
Web: SoloGambas seleccion de articulos dedicados a Gambas
Visita el Curso de Gambas3 ¡¡¡Gratuito!!!
 
jsbsan - Ver perfil del usuarioEnviar mensaje privadoVisitar sitio web del usuario 
Volver arribaPágina inferior
Responder citando   Descargar mensaje  
Mensaje Re: Detectar Modificacion Al Pegar Texto En Textarea 
 
Si lo que pretendes es activar el "btnGuardar" cuando se modifique el TextArea, podías desactivarlo en Form_Open después de cargar el fichero y en _Change activarlo.
Public Sub Form_Open()

  Me.Title = "Notas"
  Me.Center
  LabVersion.Text = FMain.NumVersion
  
  RutaNotas = FMain.TemaEstudio &/ "Notas.txt"
  If Not Exist(RutaNotas) Then
    File.Save(RutaNotas, "")
  Else
    TextArea1.Text = File.Load(RutaNotas)  <------ esto lanza un evento change
    btnGuardar.Enabled = False
  Endif

End

Public Sub TextArea1_Change()
 
     btnGuardar.Enabled = True
End

 


Creo que es eso lo que pretendes, ¿no?
Saludos

PD: Ahora de "coña". La solución del Timer (que no para nunca) me ha recordado una canción de Parade: " Qué triste es ser electrón, vivir en una nube, el electrón se aburre por definición."
 
 



 
frajanic - Ver perfil del usuarioEnviar mensaje privado 
Volver arribaPágina inferior
Responder citando   Descargar mensaje  
Mensaje Re: Detectar Modificacion Al Pegar Texto En Textarea 
 
v3ctor escribió: [Ver mensaje]
...al cargar el formulario se producen un evento change


Yo propono esto:
Public Sub Form_Open()

  Me.Title = "Notas"
  Me.Center
 
  LabVersion.Text = FMain.NumVersion
  
  RutaNotas = FMain.TemaEstudio &/ "Notas.txt"
  If Not Exist(RutaNotas) Then
    File.Save(RutaNotas, "")
  Else
    Object.Lock(TextArea1)   ' Vamos bloquear cada evento de la TextArea
    TextArea1.Text = File.Load(RutaNotas)
  Endif

    Object.Unlock(TextArea1)    ' Desbloqueamos comoquiera todos los eventos de la TextArea

End

 



 
vuott - Ver perfil del usuarioEnviar mensaje privado 
Volver arribaPágina inferior
Responder citando   Descargar mensaje  
Mensaje Re: Detectar Modificacion Al Pegar Texto En Textarea 
 
interesante vuott

así quedo y funciona (lo que no quiere decir que sea una programación correcta o inteligente)

' gambas class file

Private Modificado As Boolean = False
Private Cargado As Boolean = True
Private RutaNotas As String


Public Sub Form_Open()

  Me.Title = "Notas"
  Me.Center
  LabVersion.Text = FMain.NumVersion
  
  RutaNotas = FMain.TemaEstudio &/ "Notas.txt"
  If Not Exist(RutaNotas) Then
    File.Save(RutaNotas, "")
  Else
    TextArea1.Text = File.Load(RutaNotas)
  Endif
  
End

Public Sub btnSalir_Click()
  VerificarModificacion()
End

Public Sub btnClear_Click()
 Dim respuesta As Byte
 
If Len(TextArea1.Text) = 0 Then Return
 respuesta = Message.Warning("Se borrara todo el documento, estas seguro?", "Sí borra", "Me arrepiento")
 Select Case respuesta
   Case 1
     Cargado = True
     Modificado = False
     btnGuardar.Enabled = False
     TextArea1.Clear
     TextArea1.SetFocus
     File.Save(RutaNotas, "")
   Case 2
     TextArea1.SetFocus
     Return
 End Select
  
End

Public Sub btnGuardar_Click()
  File.Save(RutaNotas, TextArea1.Text)
  Modificado = False
  btnGuardar.Enabled = False
  TextArea1.SetFocus
End

Public Sub Form_Close()
   If Modificado Then Stop Event
   FMain.btnNotas.Enabled = True
End

Public Sub TextArea1_KeyRelease()
  Modificado = True
  btnGuardar.Enabled = True
  TextArea1.SetFocus
End

Private Sub VerificarModificacion()
  Dim respuesta As Byte
  
  If Modificado = True Then
   respuesta = Message.Warning("Notas fue modificadio!", "Salir sin guardar", "Guardar y salir", "Volver")
  
   Select Case respuesta
     Case 1
       Goto Salir
     Case 2
       File.Save(RutaNotas, TextArea1.Text)
       Goto Salir
     Case 3
       Return
   End Select
  Endif
  
  Salir:
  Modificado = False
  Me.Close
  
End

Public Sub btnGuardar_Enter()

  If btnGuardar.Enabled = True Then
    btnGuardar.Tooltip = "Guardar cambios" & gb.NewLine & RutaNotas
  Endif

End

Public Sub TextArea1_Change()
 
 If Cargado = True Then
   Cargado = False
 Else
   Modificado = True
   HayModificacion(Modificado)
 Endif
 
End

Public Sub HayModificacion(si As Boolean)
  
  If si = True Then
    If Cargado = False Then
      btnGuardar.Enabled = True
    Else
      btnGuardar.Enabled = False
    Endif
  Else
    btnGuardar.Enabled = False
  Endif
  
End


Public Sub btnGuardarComo_Click()

  Dialog.Path = FMain.TemaEstudio & "/"
  If Dialog.SaveFile() Then Return
  File.Save(Dialog.Path, TextArea1.Text)

End


 zznotas
 




===================
Software libre, programación libre, vida libre es la Public function Libertad()as Invendible
Proyectos: VisorRV1960,Taller2015,Tanteador
https://sourceforge.net/u/v3ctor-full/profile/
Blog: http://novatocodegambas.blogspot.com.uy/
 
última edición por v3ctor el Miercoles, 08 Julio 2015, 23:47; editado 1 vez 
v3ctor - Ver perfil del usuarioEnviar mensaje privadoVisitar sitio web del usuario 
Volver arribaPágina inferior
Responder citando   Descargar mensaje  
Mensaje Re: Detectar Modificacion Al Pegar Texto En Textarea 
 
Si funciona, ¡PERFECTO!
¿Qué es mejor o peor?
Es TU solución.
¡Enhorabuena!
Saludos.
 



 
frajanic - Ver perfil del usuarioEnviar mensaje privado 
Volver arribaPágina inferior
Mostrar mensajes anteriores:    
 
OcultarTemas parecidos
Tema Autor Foro Respuestas último mensaje
No hay nuevos mensajes De Textedit A Textarea Modo Texto. pittusa General 1 Viernes, 23 Julio 2010, 18:42 Ver último mensaje
abarzuaf
No hay nuevos mensajes Color De El Texto De Un Textarea En Report kingworld General 0 Viernes, 25 May 2012, 01:27 Ver último mensaje
kingworld
No hay nuevos mensajes Como Hago Para Que Un Textbox No Admita Pe... elitedigital2005 General 7 Miercoles, 27 Abril 2016, 13:04 Ver último mensaje
shordi
No hay nuevos mensajes Se Desarma El Texto! De Un Txt A Un Textarea! v3ctor General 8 Jueves, 03 Agosto 2017, 19:47 Ver último mensaje
jsbsan
 

Publicar nuevo tema  Responder al tema  Página 1 de 1
 

Usuarios navegando en este tema: 0 registrados, 0 ocultos y 1 invitado
Usuarios registrados conectados: Ninguno


 
Lista de permisos
No puede crear mensajes
No puede responder temas
No puede editar sus mensajes
No puede borrar sus mensajes
No puede votar en encuestas
No puede adjuntar archivos
Puede descargar archivos
No puede publicar eventos en el calendario



  

 

cron