生活已是百般艰难,为何不努力一点。下面图老师就给大家分享取得TextBox 某一行的字串,希望可以让热爱学习的朋友们体会到设计的小小的乐趣。
【 tulaoshi.com - 编程语言 】
这是使用EM_GETLINE message来做,比较奇特的是lParam是指向一个字串所在的位置,但是该字串传入时,前两个Byte要存该字串允许的最大长度。
(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/bianchengyuyan/)
'以下在Form需一个TextBox,并设定MultiLine = True, 一个Command ButtonPrivate Sub Command1_Click()Dim str5 As Stringstr5 = GetaLine(Text1,1) '取得第二行的字串,以0为基底End Sub'以下在.BasOption ExplicitConst EM_GETLINE = &HC4Declare Function SendMessage Lib "user32" Alias "SendMessageA" _ (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _ lParam As Any) As LongPublic Function GetaLine(Text1 As TextBox, ByVal ntx As Long) As StringDim str5(255) As Byte '如果您的字串 255 byte请自行增加该Byte ArrayDim str6 As String, i As Longstr5(0) = 255 '字串的前两个Byte存该字串的最大长度str5(0) = 255i = 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 IfEnd Function(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/bianchengyuyan/)
来源:http://www.tulaoshi.com/n/20160219/1613352.html
看过《取得TextBox 某一行的字串》的人还看了以下文章 更多>>