Author | Message | Time |
---|---|---|
Camel | Does anybody know if it's possible in VB to prevent a textbox from inserting the tab charactor when I press ctrl+I? | August 19, 2003, 4:18 AM |
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. | August 19, 2003, 9:08 AM |
j0k3r | 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... [code] Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = vbkeyctrl And KeyCode = vbKeyI Then 'do nothing End If End Sub [/code] 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] | August 19, 2003, 11:34 AM |
Skywing | [quote author=j0k3r link=board=5;threadid=2386;start=0#msg18699 date=1061292843] Ummmmm I didn't even know that ctrl+I adds a tab character... [/quote] 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. | August 19, 2003, 1:25 PM |
Adron | [quote author=Skywing link=board=5;threadid=2386;start=0#msg18710 date=1061299541] 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. [/quote] 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... | August 19, 2003, 3:47 PM |
ioSys | Any of these two is possible to use i think. dont know if this is working.. maybe it does. [code] 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 [/code] | August 19, 2003, 9:56 PM |
Adron | [quote author=ioSys link=board=5;threadid=2386;start=0#msg18732 date=1061330180] Any of these two is possible to use i think. dont know if this is working.. maybe it does. [/quote] Those won't work. Try this: [code] 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 [/code] | August 20, 2003, 4:00 PM |
Camel | Thanks Adron, +1 | August 21, 2003, 3:45 AM |
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. [code]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[/code] | August 21, 2003, 7:52 AM |
Adron | [quote author=Grok link=board=5;threadid=2386;start=0#msg18786 date=1061452340] 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. [code]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[/code] [/quote] 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 :) | August 21, 2003, 10:31 AM |
Grok | [quote author=Adron link=board=5;threadid=2386;start=0#msg18790 date=1061461888] 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 :)[/quote] Haha, yeh. | August 21, 2003, 11:41 AM |
Camel | 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... [code]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[/code] | August 21, 2003, 11:43 PM |