VB编程中所提到的缩进规则是什么意思?

VB编程中所提到的缩进规则是什么意思?,第1张

vb6没有自动缩孝蔽进规则,只有延续上行内容缩进 缩进是为了让你的程序代码结构亩慎手清晰,便于阅读,在某些企业会严格要求程序员的代码质量,除了注释,缩进也占一部分 你可以在菜迅嫌单 tools -- editor 中选中 Auto indent,实现缩进

Private position(1024) As Integer '用来记录每段首行位置的数组

Private currentposition As Integer = 0

Private rtb_Selectionlen As Integer = 0

Private rtb As RichTextBox

'首行缩进

Public Sub SetFirstLineIndent()

'获取当前插入运镇陆点的位置

currentposition = rtb.GetFirstCharIndexOfCurrentLine

rtb_Selectionlen = rtb.SelectionLength

'找出全部换行符的位置并存入数组中

Call FindFirstCharOfParagraph()

'找到插入点所在段落的首字符位置

FindPositonofFirstChar()

'进行首行缩进

InsertIndent(firstlineindentvalue)

End Sub

'找出全部段落首行首字符的位置并存入数组中

Public Sub FindFirstCharOfParagraph()

Dim indexofposition As Integer = 0

Dim startposition As Integer = 0

Dim indexofarray As Integer = 1 '数组的索引从1开始,因为0已经被缺省

position(0) = 0 '将旁顷第一段定为0

Do

indexofposition = rtb.Find(Chr(13), startposition, RichTextBoxFinds.None)

If indexofposition >旅液= 0 Then

position(indexofarray) = indexofposition + 1 '当前换行符的位置加1就等于下一段的首字符位置

startposition = indexofposition + 1

indexofarray += 1

Else

'MsgBox("未找到!")

End If

Loop While indexofposition >= 0

End Sub

'获取当前字符所在行的首字符位置

Public Function FindPositionOfCurrentLine() As Integer

currentposition = rtb.GetFirstCharIndexOfCurrentLine

rtb_Selectionlen = rtb.SelectionLength

Return currentposition

End Function

在keydown过程写代码

如果keycode=13(回车的话)

发送(SP)(TAB)(SP)给文本框,

然后再回车

=============

看你喜欢了,vb的空格可以控制

space(10),就是10个空格了

tab写法是vbTab,回车换行时森余vbCrLf

我开始没有明白你sp的意思,如果是空格加tab,简单,这帆春肆态轿样

'如果输入回车,自动添加4个空格,一个tab,4个空格到下一行开始

if keycode=13 then

text1.text= text1.text &vbcrlf &space(4) &vbtab &space(4)

end if

如果你不要那么多空格,或者多几个/少几个tab,自己改啦,

知道怎么改就行了


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12397370.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-25
下一篇 2023-05-25

发表评论

登录后才能评论

评论列表(0条)

保存