• Welcome to Valhalla Legends Archive.
 

Textbox...

Started by Camel, August 18, 2003, 11:18 PM

Previous topic - Next topic

Camel

Does anybody know if it's possible in VB to prevent a textbox from inserting the tab charactor when I press ctrl+I?

Yoni

Something with KeyDown I think. Maybe KeyPress. Dunno. Involves checking a parameter for vbTab and setting it to zero. Something like that. This didn't come from me.

j0k3r

#2
Ummmmm I didn't even know that ctrl+I adds a tab character... Why would you want to prevent that anyways? Oh well here goes...


Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

If KeyCode = vbkeyctrl And KeyCode = vbKeyI Then
'do nothing
End If

End Sub


I'm not actually sure if vbkeyctrl is the proper key... and I don't know how to make it do nothing... But you might be a general idea.
[Edit]I tried it with a textbox, I didn't notice any tab thing...[/edit]
QuoteAnyone attempting to generate random numbers by deterministic means is, of course, living in a state of sin
John Vo

Skywing

#3
Quote from: j0k3r on August 19, 2003, 06:34 AM
Ummmmm I didn't even know that ctrl+I adds a tab character...
Conventionally ctrl-X where X is an alpha character inserts the ASCII character code minus 'a' or 'A', depending on whether caps is on or not.

I would insert character 9, also known as \t or tab.
This is why you can telnet to Battle.net and use ctrl-c to send character 3, registering yourself as a chat connection.

Adron

Quote from: Skywing on August 19, 2003, 08:25 AM
Conventionally ctrl-X where X is an alpha character inserts the ASCII character code minus 'a' or 'A', depending on whether caps is on or not.

Minor error: It inserts the ASCII character code minus 'a' or 'A' plus one. Otherwise Ctrl-A would be ascii 0, Ctrl-C ascii 2 and Ctrl-I ascii 8...

ioSys

#5
Any of these two is possible to use i think.
dont know if this is working.. maybe it does.


Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
if keyascii = vbctrl and vbkeyi then
keyascii = 0
end if
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
if keyascii = vbctrl and vbkeyi then
keyascii = 0
end if
End Sub

Adron

#6
Quote from: ioSys on August 19, 2003, 04:56 PM
Any of these two is possible to use i think.
dont know if this is working.. maybe it does.

Those won't work. Try this:


Private canceltab As Long
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
 If KeyCode = vbKeyI And Shift = vbCtrlMask Then canceltab = canceltab + 1
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
 If KeyAscii = 9 And canceltab > 0 Then canceltab = canceltab - 1: KeyAscii = 0
End Sub

Camel


Grok

Users will still be able to paste strings that include Tab characters into your text box.  To handle all situations, use the Change event of the TextBox, and remove any Tabs with Replace.

Private Sub Text1_Change()
   If InStr(Text1.Text, vbTab) Then
       Text1.Text = Replace(Text1.Text, vbTab, "")
   End If
   Text1.SelStart = Len(Text1.Text)
End Sub


Adron

Quote from: Grok on August 21, 2003, 02:52 AM
Users will still be able to paste strings that include Tab characters into your text box.  To handle all situations, use the Change event of the TextBox, and remove any Tabs with Replace.

Private Sub Text1_Change()
   If InStr(Text1.Text, vbTab) Then
       Text1.Text = Replace(Text1.Text, vbTab, "")
   End If
   Text1.SelStart = Len(Text1.Text)
End Sub



That's a totally different question though... I went to great trouble to ensure that tabs could be inserted, as long as they were not inserted using the Ctrl-I key :)

Grok

Quote from: Adron on August 21, 2003, 05:31 AM
That's a totally different question though... I went to great trouble to ensure that tabs could be inserted, as long as they were not inserted using the Ctrl-I key :)

Haha, yeh.

Camel

#11
Right; I don't want to disable tabs all togeather, I just want to use ctrl+I to insert "ÿCi" instead of a tab :)

[edit] Might as well post it...
Private Sub txtSend_KeyDown(KeyCode As Integer, Shift As Integer)
   'thx Adron for the canceltab idea
   If (KeyCode = vbKeyI) And CBool(Shift And vbCtrlMask) Then
       canceltab = canceltab + 1
   End If
End Sub

Private Sub txtSend_KeyPress(KeyAscii As Integer)
   If (KeyAscii = vbKeyTab) And (canceltab > 0) Then
       canceltab = canceltab - 1
       KeyAscii = 0
   End If
End Sub

Private Sub txtSend_KeyUp(KeyCode As Integer, Shift As Integer)
...
   If (KeyCode = vbKeyB) And CBool(Shift And vbCtrlMask) Then
       x = txtSend.SelStart
       If txtSend.SelLength = 0 Then
           txtSend.SelText = "ÿCb"
       Else
           txtSend.SelText = "ÿCb" & txtSend.SelText & "ÿCb"
       End If
   End If
   
   If (KeyCode = vbKeyI) And CBool(Shift And vbCtrlMask) Then
       x = txtSend.SelStart
       If txtSend.SelLength = 0 Then
           txtSend.SelText = "ÿCi"
       Else
           txtSend.SelText = "ÿCi" & txtSend.SelText & "ÿCi"
       End If
   End If
...
End Sub