取得TextBox某一行的字串

來源:互聯網
上載者:User

 內容摘要:這是使用EM_GETLINE message來做,比較奇特的是lParam是指向一個字串所在的位置, 但是該字串傳入時,前兩個Byte要存該字串允許的最大長度。   以下在Form需一個…

 

這是使用EM_GETLINE message來做,比較奇特的是lParam是指向一個字串所在的位置, 但是該字串傳入時,前兩個Byte要存該字串允許的最大長度。

'以下在Form需一個TextBox,並設定MultiLine = True, 一個Command Button

Private Sub Command1_Click()

Dim str5 As String

str5 = GetaLine(Text1,1) '取得第二行的字串,以0為基底

End Sub

'以下在.Bas

Option EXPlicit

Const EM_GETLINE = &HC4

Declare Function SendMessage Lib "user32" Alias "SendMessageA" _

(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _

lParam As Any) As Long

Public Function GetaLine(Text1 As TextBox, ByVal ntx As Long) As String

Dim str5(255) As Byte '如果您的字串 > 255 byte請自行增加該Byte Array

Dim str6 As String, i As Long

str5(0) = 255 '字串的前兩個Byte存該字串的最大長度

str5(0) = 255

i = SendMessage(Text1.hwnd, EM_GETLINE, ntx, str5(0))

If i = 0 Then

GetaLine = ""

Else

str6 = StrConv(str5, VBUnicode)

GetaLine = Left(str6, InStr(1, str6, Chr(0)) - 1)

End If

End Function

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.