我们知道TextBox的MultiLine属性可让文本框在回车时自动换行,但是为只读属性,不可以在运行时控制是否换行,为了在运行时控制文稿本框是否换行,我使用以下API:
    Dim lResult As Long
    Dim lStyle As Long    'Text1为文本框
    lStyle = GetWindowLong(Text1.hwnd, GWL_STYLE)
    lResult = SetWindowLong(Text1.hwnd, GWL_STYLE, lStyle Or ES_MULTILINE )     但我发现回车以后,并不换行,这是为什么?请高手指点!!!!!!!!
 

解决方案 »

  1.   

    查查msdn中关于Edit Control Styles的说明ES_MULTILINE这个类型不能在setwindowlong中设置
      
     Designates a multiline edit control. The default is single-line edit control. 
    When the multiline edit control is in a dialog box, the default response to pressing the ENTER key is to activate the default button. To use the ENTER key as a carriage return, use the ES_WANTRETURN style.When the multiline edit control is not in a dialog box and the ES_AUTOVSCROLL style is specified, the edit control shows as many lines as possible and scrolls vertically when the user presses the ENTER key. If you do not specify ES_AUTOVSCROLL, the edit control shows as many lines as possible and beeps if the user presses the ENTER key when no more lines can be displayed.If you specify the ES_AUTOHSCROLL style, the multiline edit control automatically scrolls horizontally when the caret goes past the right edge of the control. To start a new line, the user must press the ENTER key. If you do not specify ES_AUTOHSCROLL, the control automatically wraps words to the beginning of the next line when necessary. A new line is also started if the user presses the ENTER key. The window size determines the position of the wordwrap. If the window size changes, the wordwrapping position changes and the text is redisplayed.Multiline edit controls can have scroll bars. An edit control with scroll bars processes its own scroll bar messages. Note that edit controls without scroll bars scroll as described in the previous paragraphs and process any scroll messages sent by the parent window.
    只能在createwindow中设置而ES_LOWERCASE Converts all characters to lowercase as they are typed into the edit control. 
    To change this style after the control has been created, use SetWindowLong. 
    可在setwindowlong设置
      

  2.   

    在要换行的地方加入vbcrlf,例如
    "abcdefg" & Vbcrlf & "hijklmn"
    就会实现换行了.记得之前把TextBox的MultiLine属性设置为True
      

  3.   

    也可以用“aasdfg”& vbnewline