將RichTextBox設定為自動換行或非自動換行 (轉)

worldblog發表於2007-12-14
將RichTextBox設定為自動換行或非自動換行 (轉)[@more@]

  近日研究文字和字串,研究得頭混腦脹,問題真是太多了。
  這只是其中的一個問題,答案來自問專家網站和CSDN的/Message_Board/Send.?sendto=TechnoFantasy" target=_blank>TechnoFantasy() ,解決如下:

Public Const WM_USER = &H400
Public Const EM_SETTARGETDEVICE = (WM_USER + 72)

Public Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
Public 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 Sub AutoSwitchLine(ByRef RichText As Long, ByVal bSwitch As Boolean)
  If bSwitch Then
  '設定 RichTextBox 自動換行
  Call SendMessage(RichText.hWnd, EM_SETTARGETDEVICE, _
  GetDC(RichText.hWnd), RichText.Width / 15)
  If RichText.RightMargin = 0 Then
  RichText.RightMargin = 1
  Else
  RichText.RightMargin = 0
  End If
  Else
  '設定 RichTextBox 不自動換行
  Call SendMessage(RichText.hWnd, EM_SETTARGETDEVICE, 0, 1)
  End If
End Sub


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10752043/viewspace-993387/,如需轉載,請註明出處,否則將追究法律責任。

相關文章