RichTextBox如何选择指定行并行的字体改变?比容我先在RichTextBox固定了下面的内容,然后我想将其中的任何
RichTextBox如何选择指定行并行的字体改变?
比容我先在RichTextBox固定了下面的内容,然后我想将其中的任何一行字体改变应该怎么做呢?我无论用换行或是回车或是vbNewLine都不知道怎么才能获得任意行并将行内容字体改变.
菜鸟一直没搜到结果,请指点!
RichTextBox1.Text = "123456789" & vbNewLine & "555684" & Chr(13)
RichTextBox1.Text = RichTextBox1.Text & Chr(10) & "求带Gadgets ActiveX Pro解方法"
RichTextBox1.Text = RichTextBox1.Text & Chr(10) & "网上下的应该是被强爆了的,但好象不干净只能在本机上使用,将控件用到别的机器上一样是没有许可证的,我试过,但水平有"
RichTextBox1.Text = RichTextBox1.Text & Chr(10) & "限用OD这些东西将它附加到进程或是什么的都不能运行,问过多次如何使用OD的时候程序能正常运行无果,求带"
RichTextBox1.Text = RichTextBox1.Text & Chr(10) & "同时将Gadgets ActiveX Pro一并上传,东西不错"
RichTextBox1.Text = RichTextBox1.Text & Chr(10) & "设置键盘事件优先"
[解决办法]'下面的程序可以区分软回车与硬回车,解决你的问题足够用了
'add a textbox with "multiline=true","scrollbars=2".
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 Declare Function SendMessageByNum Lib "USER32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function SendMessageByString Lib "USER32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Private Const EM_LINEINDEX = &HBB
Private Const EM_GETLINECOUNT = &HBA
Private Const EM_GETLINE = &HC4
Private Const EM_LINELENGTH = &HC1
Private Sub Form_Load()
Dim a(25) As String, i As Long
For i = 0 To 25
a(i) = String(50, Chr(i + 97))
Next
RTB.Text = Join(a, "CSDN")
End Sub
Private Sub Command1_Click()
MsgBox GetLineWithStr(RTB, "CSDN"), 0, "包含“CSDN”的行"
End Sub
Function GetLineText(ByVal txtbox As RichTextBox, ByVal LineIndex As Long) As String '返回指定行的内容
Dim LC As Long, LineChar As Long
LineChar = SendMessageByNum(txtbox.hWnd, EM_LINEINDEX, LineIndex, 0)
LC = SendMessageByNum(txtbox.hWnd, EM_LINELENGTH, LineChar, 0) + 1
GetLineText = String(LC + 2, 0)
Mid(GetLineText, 1, 1) = Chr(LC And &HFF)
Mid(GetLineText, 2, 1) = Chr(LC \ &H100)
LC = SendMessageByString(txtbox.hWnd, EM_GETLINE, LineIndex, GetLineText)
GetLineText = Left(GetLineText, LC)
End Function
Function GetLineWithStr(ByVal txtbox As RichTextBox, ByVal mystr As String) As String
Dim linecount As Long, temp() As String, i As Long
linecount = SendMessage(txtbox.hWnd, EM_GETLINECOUNT, 0, 0) '返回行数
ReDim temp(1 To linecount)
For i = 1 To linecount
temp(i) = "第" & i & "行:" & GetLineText(txtbox, i - 1) '添加行号
Next
GetLineWithStr = Join(Filter(temp, mystr), vbCrLf) ' 字符串过滤
Erase temp
End Function