|
|
|
|
|
|
| |
| |
| |
| |
|
Se Recomienda Resolución de 800x600 pixels |
|
2da PARTE 1.-
Posicionar el cursor al final de una línea de texto Ya sabes cómo seleccionar todo el texto de un TextBox,
ahora puedes usar esto para posicionarte al final: Text1.SetFocus
'Asegurarnos que reciba el foco Text1.SelStart = Len(Text1)
'La posición del caracter inicial es la
longitud del texto...
'por tanto se posiciona al final
2.- Acceder a un control por la tecla rápida
sin necesidad de pulsar ALT+letra. Este "truco" servirá para aquellos forms en los
que necesitemos acceder a distintos controles que tienen una tecla de acceso rápido,
pero sin necesidad de pulsar la combinación de teclas: Alt+letra_de_acceso. Este código funciona en cualquier versión de Visual
Basic, en la versión 1 y 2 no lo he probado... ¿alguien las usa? Sub Form_KeyPress (KeyAscii As Integer)
'Comprobar si la tecla pulsada coincide con
'alguna de acceso rápido
'
'NOTAS:
' Debe
estar puesto Option Compare Text
' El
KeyPreview del Form debe estar a True
' Esto
no es demasiado útil si hay TextBoxes
' ya que no podrás escribir los caracteres
' de acceso rápido
' Pero para cualquier otra aplicación está bien
'
Dim ch As String
Dim i%, j%
'Detectar los errores producidos
'al encontrar controles sin Caption
On Local Error Resume Next
ch = Chr$(KeyAscii)
'Un bucle para todos los controles de este form
For i = 0 To Me.Controls.Count - 1
j = InStr(Me.Controls(i).Caption, "&"
& ch)
'Si tiene un código de acceso rápido...
If j Then
'Esto es para que descarte la tecla pulsada
KeyAscii = 0
'Enviamos la pulsación Alt+tecla
SendKeys "%" & ch
'nada más que hacer
Exit For
End If
Next
'Si se ha producido un error...
Err = 0
'restaurar la rutina de detección de errores
On Local Error GoTo 0 End Sub
3.- Para los que tenemos poca
memoria... y VB5 Realmente es una chorradilla de truco, pero lo mismo a tí
no se te había ocurrido... (la verdad es que a mí tampoco...)
4.- Cómo simular sobreescribir e
insertar en un TextBox Este
truco está sacado de la Microsoft Knowledge Base - How to Emulate Overtype Mode
in a Visual Basic Text Box, ID del Artículo: Q96210, por eso los comentarios
los he dejado en inglés. Lo único que yo he añadido es el código del evento
Text1_KeyDown para que funcione bien al mover el cursor si estamos en modo
INSERT. Este es el código, lo del Label es sólo a título
informativo. ¡Que lo disfrutes! Option Explicit Const MODE_OVERTYPE =
"overtype" Const MODE_INSERT = "insert" Private Sub Form_Load()
Text1.Tag = MODE_INSERT
Label1.Caption = MODE_INSERT End Sub Private Sub Text1_Change()
' You have taken some action that changed the text
in the
' text box. Reset the SelLength if you are in
overtype mode.
If Text1.Tag = MODE_OVERTYPE And Text1.SelLength =
0 Then
Text1.SelLength = 1
End If End Sub Private Sub Text1_KeyDown(KeyCode As
Integer, Shift As Integer)
'
'Esto es para manejar bien el movimiento del cursor
'
Select Case KeyCode
' Handle keys that move the caret position and
reset the
' SelLength if you are in overtype mode:
Case vbKeyLeft, vbKeyRight, vbKeyUp, vbKeyDown,
vbKeyHome, vbKeyEnd, vbKeyPageUp, vbKeyPageDown
If Text1.Tag = MODE_OVERTYPE Then
Text1.SelLength = 0
End If
End Select End Sub Sub Text1_KeyPress(KeyAscii As Integer)
' If you press BACKSPACE and are in overtype mode,
' then set SelLength to 0 so the backspace
will correctly
' delete the character to the left of the current
caret
' position. SelLength will be reset when the
Text1_Change
' event occurs following the backspace.
If KeyAscii = vbKeyBack And Text1.Tag =
MODE_OVERTYPE Then
Text1.SelLength = 0
End If End Sub Private Sub Text1_KeyUp(KeyCode As
Integer, Shift As Integer)
Select Case KeyCode
' Toggle between insert and overtype modes.
Case vbKeyInsert
If Text1.Tag = MODE_OVERTYPE Then
Text1.Tag = MODE_INSERT
Label1.Caption = MODE_INSERT
Else
Text1.SelLength = 1
Text1.Tag = MODE_OVERTYPE
Label1.Caption = MODE_OVERTYPE
End If
' Handle keys that move the caret position and
reset the
' SelLength if you are in overtype mode:
Case vbKeyLeft, vbKeyRight, vbKeyUp, vbKeyDown,
vbKeyHome, vbKeyEnd, vbKeyPageUp, vbKeyPageDown
If Text1.Tag = MODE_OVERTYPE Then
Text1.SelLength = 1
End If
End Select End Sub Private Sub Text1_MouseUp(Button As
Integer, Shift As Integer, X As Single, Y As Single)
' You have clicked at a new location within the
text box. Reset the
' SelLength if you are in overtype mode.
If Text1.Tag = MODE_OVERTYPE And Text1.SelLength =
0 Then
Text1.SelLength = 1
End If End Sub 5.-
Limitar la entrada de un TextBox sólo a números Realmente la base del truco es el uso de la función
IsNumeric, el problema que había era que si se introducía un número decimal
menor que 1, había que poner el CERO delante del signo decimal, este caso se
resuelve añadiendo ese CERO al valor que se le pasa a esta función... con lo
cual acepta cualquier número... Private Sub Text1_KeyPress(KeyAscii As
Integer)
If KeyAscii = 13 Then
KeyAscii = 0 'Para que no "pite"
SendKeys "{tab}" 'Envia una pulsación TAB
ElseIf KeyAscii <> 8 Then 'El 8 es la tecla de borrar (backspace)
'Si después de añadirle
la tecla actual no es un número...
If Not IsNumeric("0" & Text1.Text
& Chr(KeyAscii)) Then
'...
se desecha esa tecla y se avisa de que no es correcta
Beep
KeyAscii = 0
End If
End If End Sub
6.- Justificar el contenido de un
TextBox El tema de la justificación del contenido de un textbox
es algo simple de solucionar, para ello se debe asignar a la propiedad Multiline
el valor True, de esta forma la propiedad Alignment funciona correctamente.
7.- Mostrar los elementos de un
ComboBox mientra se escribe Esto
no es nada nuevo, pero es una ampliación de un truco anterior y de una de las
colaboraciones. Escribe el siguiente código en el form que
contenga el Combo: Private Sub
Combo1_Change(Index As Integer)
Static YaEstoy As Boolean
On Local Error Resume Next
If Not YaEstoy Then
YaEstoy = True
unCombo_Change Combo1(Index).Text, Combo1(Index)
YaEstoy = False
End If
Err = 0 End Sub Private Sub
Combo1_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)
unCombo_KeyDown KeyCode End Sub Private Sub
Combo1_KeyPress(Index As Integer, KeyAscii As Integer)
unCombo_KeyPress KeyAscii End Sub Añade
estas declaraciones y procedimientos en un módulo BAS, Option Explicit Dim Combo1Borrado As
Boolean Public Sub
unCombo_KeyDown(KeyCode As Integer)
If KeyCode = vbKeyDelete Then
Combo1Borrado = True
Else
Combo1Borrado = False
End If End Sub Public Sub
unCombo_KeyPress(KeyAscii As Integer)
'si se pulsa Borrar... ignorar la búsqueda al cambiar
If KeyAscii = vbKeyBack Then
Combo1Borrado = True
Else
Combo1Borrado = False
End If End Sub Public Sub
unCombo_Change(ByVal sText As String, elCombo As ComboBox)
Dim i As Integer, L As Integer
If Not Combo1Borrado Then
L = Len(sText)
With elCombo
For i = 0 To .ListCount - 1
If StrComp(sText, Left$(.List(i), L), 1) = 0 Then
.ListIndex = i
.Text = .List(.ListIndex)
.SelStart = L
.SelLength = Len(.Text) - .SelStart
Exit For
End If
Next
End With
End If End Sub
©1998-2001 FMC Webs® Todos los derechos Reservados. Ferraro Mauro - San Nicolás - Argentina |
||||
|
El Codigo del Mes Aqui le mostraremos el Codigo Fuente del Mes, Votalo Ya!!! Preguntar Tutoriales Contactenos Redirecciona tu Pagina Gratis!!! Votanos en La web del Programador
|