一个TextBox, multiline属性为true,我将让它每行的内容满10个字符时就自动换行,这只要调整Textbox的宽度就行了。问题是:假设我想显示"0123456789 012345"这样一串内容,希望是第一行显示"0123456789",第二行显示" 012345",可实际显示结果却是第一行显示为"0123456789 ",第二行显示为"012345"。也就是空格没有显示到第二行开头。请问有什么办法解决这个行末空格的显示问题?
调试欢乐多
string1=replace(string1," ",vbnewline)
text1.text=string1哈哈over
when you use the stirng ,you can replace vbcrlf & " " , " "
as a num 的 补数 的 补数 是 the num.
blow is right
sub textchange()
dim a as string
a=text1.text
replace a,vbcrlf,""
if len(a) mod 10 =0 then
text1.text=text1.text+vbcrlf
end
如果我输入的文本中也有回车换行符 & " "呢?
就好像输入一段文字后回车另起一行,然后空两格,再输入一段文字。这时上下两段交接的地方不正好也是vbcrlf & " "?
而且这个vbcrlf又是我自己输入的,不能简单的用replace vbcrlf & " " , " "来把它替换掉的。也许我有点罗嗦,但事实是我确实有点束手无策。
you need when a person input 10 char in a line, program auto return,but when the person wrtie a line into next line ,thus at the moment he find priview line ,he write erorr,but he not use back space but use mouse point to error position, he not let he not want vbcrlf legal exisit.
you can let you want do thing say to me?
Text1.Text = vbCrLf
Text1.SelStart = 0
End SubPrivate Sub Text1_Change()
If Len(Text1.Text) > 0 And Len(Text1.Text) Mod 12 = 0 Then
Text1.Text = Text1.Text & vbCrLf
End If
Text1.SelStart = Len(Text1.Text) - 2
End Sub
vb6+2k下调试通过。楼主可以试试。我比较意外的是vbcrlf是占了两个字符。
can achive your decommand.
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3195
ClientLeft = 60
ClientTop = 345
ClientWidth = 4725
LinkTopic = "Form1"
ScaleHeight = 3195
ScaleWidth = 4725
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command1
Caption = "Command1"
Height = 375
Left = 2880
TabIndex = 1
Top = 720
Width = 1215
End
Begin VB.TextBox Text1
Height = 2775
Left = 960
MultiLine = -1 'True
TabIndex = 0
Text = "txtpro.frx":0000
Top = 240
Width = 1200
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type POINTAPI
x As Long
y As Long
End Type
Dim check As Boolean
Dim r As RECT
Dim p As Long
Dim p1 As POINTAPI
Private Function PtInRect(a As POINTAPI, b As RECT) As Boolean
PtInRect = a.x < b.Right - 10 And a.x > b.Left And a.y < b.Bottom And a.y > b.Top
End Function
Private Sub Form_Load()
r.Left = 0
r.Top = 0
r.Right = (Me.Text1.Width - 110) / 15
r.Bottom = (Me.Text1.Height - 110) / 15
SendMessage Me.Text1.hwnd, &HB3, 0, r
End SubPrivate Sub Text1_Change()
If check Then
p = SendMessage(Me.Text1.hwnd, 214, Len(Me.Text1.Text) - 1, 0)
Dim y As Integer
p1.y = p / 65536
p1.x = p And &HFFIf CBool(PtInRect(p1, r)) Then
MsgBox p1.x & " " & r.Right
End If
End If
End SubPrivate Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 32 Then
check = True
Else
check = False
End If
End Sub
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3195
ClientLeft = 60
ClientTop = 345
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 3195
ScaleWidth = 4680
StartUpPosition = 3 '窗口缺省
Begin VB.TextBox Text1
Height = 1095
Left = 1680
MaxLength = 10
MultiLine = -1 'True
TabIndex = 0
Text = "textredo.frx":0000
Top = 840
Width = 1815
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim pass As Integer
Dim linecnt As Integer
Private Sub Text1_Change()
linecnt = ((Len(Me.Text1) + 1) \ 12)
CurrentX = 0
CurrentY = 0
Print linecnt, Len(Me.Text1)
If pass = 8 Or pass = 46 Then
If linecnt > 1 Then
Me.Text1.MaxLength = 2 * linecnt + (linecnt + 1) * 10
Else
Me.Text1.MaxLength = 10
End If
End If
End SubPrivate Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
pass = KeyCode
If KeyCode = 13 Then
Me.Text1.MaxLength = Len(Me.Text1) + 10
End If
End Sub