Richtextbox中有内容时,要改变Richtextbox中的vbtab键的宽度,如何改变,为什么我用这种放法不行?
Option ExplicitPrivate Const EM_SETTABSTOPS = &HCBPrivate DlgWidthUnits As IntegerPrivate i As Long
Private lngPixelX As Long
Private TabCount As Long
Private OldHandle As Long
Private RichTextBoxHandle As LongPrivate TB As String * 1
Private StrTxtEdit As StringPrivate Declare Function GetFocus Lib "user32" () As Long
Private Declare Function GetDialogBaseUnits Lib "user32" () As Long
Private Declare Sub APISetFocus Lib "user32" Alias "SetFocus" (ByVal hwnd As Long)
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As LongPrivate Sub Form_Load()With txtEdit
    .Font.Size = "12"
    .SelText = "1" & vbTab & "4" & vbTab & "5" & vbTab & "6" & vbTab & "7" & vbTab & "8" & vbTab & "9" & vbCrLf
    .SelText = "123456789ABCDEFGHI" & vbCrLf & vbCrLf
    .SelText = vbCrLf & vbCrLf & "Notice that the default number of spaces between tabs is approximately 10, based on the RTB's default settings and the size of this font"
    .SelText = vbCrLf & vbCrLf & "This job requires dynamically setting the number of spaces between each tab, anywhere on this page, at any time, no matter how big or small the size of the form is set" & vbCrLf
End WithDim arrData() As StringtxtEdit.TabStop = TrueintTabs = GetSetting("MyApp", "myOptions", "TabSpaces", 10)MsgBox intTabsarrData = Split(txtEdit.Text, vbTab)TabCount = UBound(Split(txtEdit.Text, vbTab))ReDim TabStop(TabCount - 1)DlgWidthUnits = (GetDialogBaseUnits() Mod 65536) / 2Show
OldHandle = GetFocus()txtEdit.SetFocus
RichTextBoxHandle = GetFocus()Call SendMessage(RichTextBoxHandle, EM_SETTABSTOPS, 1, 20)txtEdit.RefreshEnd SubintTabs 是指设定的spaces数,一般是10,20,30等,请高手帮忙看看,先谢了!

解决方案 »

  1.   

    似乎RichText控件里的不是em_settabstops所希望的那个窗口类型诶……返回错误:句柄无效继续关注……
      

  2.   

    http://www.vbcity.com/forums/topic.asp?tid=50679
      

  3.   

    //,up者有分!楼主仗义,帮你UP~
      

  4.   

    Option ExplicitPrivate i As Integer
    Private j As Integer
    Private IntTabCount As IntegerPrivate Const EM_SETTABSTOPS = &HCBPrivate Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As LongPrivate Sub Form_Load()
    Dim ArrDataStr() As StringWith txtEdit
        .Font.Size = "12"
        .SelText = "1" & vbTab & "2" & vbTab & "3" & vbTab & "4" & vbTab & "5" & vbTab & "6" & vbTab & "9" & vbCrLf
        .SelText = "1234567890123456789" & vbCrLf & vbCrLf
        .SelText = vbCrLf & vbCrLf & "Notice that the default number of spaces between tabs is approximately 10, based on the RTB's default settings and the size of this font"
        .SelText = vbCrLf & vbCrLf & "This job requires dynamically setting the number of spaces between each tab, anywhere on this page, at any time, no matter how big or small the size of the form is set" & vbCrLf
    End WithintTabs = GetSetting("MyApp", "myOptions", "TabSpaces", 10)IntTabCount = UBound(Split(txtEdit.Text, vbTab))ReDim ArrData(IntTabCount)
    ReDim ArrDataLen(IntTabCount)ArrDataStr = Split(txtEdit.Text, vbTab)For i = 0 To IntTabCount
      ArrDataLen(i) = Len(ArrDataStr(i))
    Next iArrData(0) = 0For i = 0 To IntTabCount
      ArrData(i) = ArrData(i) + (ArrDataLen(i) + intTabs) * (i + 1) * 4
    Next iSendMessage txtEdit.hwnd, EM_SETTABSTOPS, IntTabCount, ArrData(0)txtEdit.RefreshEnd Sub还没有搞定,inttabs改变时没有一点变化,inttabs我一般把它设为10,20等,我想实现的功能是,
    将Richtextbox中所有的vbtab的宽度改成inttabs的值,请高手帮我看一下,顺便问一下,怎么知道
    句柄有效或无效?
    似乎RichText控件里的不是em_settabstops所希望的那个窗口类型诶……返回错误:句柄无效?
      
      

  5.   

    Option ExplicitPrivate i As Integer
    Private j As Integer
    Private IntTabCount As IntegerPrivate Const EM_SETTABSTOPS = &HCBPrivate Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long'Sub doResize()
    'txtEdit.Left = 45
    'txtEdit.Top = 45
    'txtEdit.Width = frmEdit.ScaleWidth - 180
    'txtEdit.Height = frmEdit.ScaleHeight - 180
    'End SubPrivate Sub Form_Load()
    Dim ArrDataStr() As StringWith txtEdit
        .Font.Size = "12"
        .SelText = "1" & vbTab & "2" & vbTab & "3" & vbTab & "4" & vbTab & "5" & vbTab & "6" & vbTab & "9" & vbCrLf
        .SelText = "1234567890123456789" & vbCrLf & vbCrLf
        .SelText = vbCrLf & vbCrLf & "Notice that the default number of spaces between tabs is approximately 10, based on the RTB's default settings and the size of this font"
        .SelText = vbCrLf & vbCrLf & "This job requires dynamically setting the number of spaces between each tab, anywhere on this page, at any time, no matter how big or small the size of the form is set" & vbCrLf
    End WithintTabs = GetSetting("MyApp", "myOptions", "TabSpaces", 10)MsgBox intTabsIntTabCount = UBound(Split(txtEdit.Text, vbTab))ReDim arrdata(IntTabCount)
    ReDim ArrDataLen(IntTabCount)ArrDataStr = Split(txtEdit.Text, vbTab)For i = 0 To IntTabCount
      ArrDataLen(i) = Len(ArrDataStr(i))
    Next iarrdata(0) = 0For i = 0 To IntTabCount
      If i > 0 Then
         arrdata(i) = arrdata(i - 1) + (ArrDataLen(i) + intTabs) * 4
      Else
         arrdata(i) = (ArrDataLen(i) + intTabs) * 4
      End If
    Next iSendMessage txtEdit.hwnd, EM_SETTABSTOPS, IntTabCount, arrdata(0)txtEdit.RefreshEnd Sub我改成先在这样了,还是没有反映!
      

  6.   

    可能是因为Richtextbox屏蔽了EM_SETTABSTOPS消息。
      

  7.   

    怎么使Richtextbox不屏蔽EM_SETTABSTOPS消息,给点提示,我愿试试,哪怕失败了也没有关系!
      

  8.   

    但我这个值等于SendMessage(txtEdit.hwnd, EM_SETTABSTOPS, IntTabCount, arrdata(0))=1,好象大于0就意味着成功了!
      

  9.   

    怎么使Richtextbox不屏蔽EM_SETTABSTOPS消息,给点提示,我愿试试,哪怕失败了也没有关系!
    ============================================
    如果richtextbox真的把EM_SETTABSTOPS给屏蔽掉了(现在只是猜测)那可很难办了,除非你深入到richtextbox里面去看看它的代码甚至修改它。但我这个值等于SendMessage(txtEdit.hwnd, EM_SETTABSTOPS, IntTabCount, arrdata(0))=1,好象大于0就意味着成功了!
    ===========================
    是的,说是这样子说,但就是死活没试出来,测试例子:Private Declare Function SendMessage Lib "user32" _
       Alias "SendMessageA" _
      (ByVal hwnd As Long, _
       ByVal wMsg As Long, _
       ByVal wParam As Long, _
       lParam As Any) As LongPrivate Const EM_SETTABSTOPS = &HCB
    Private Sub Command1_Click()
    'set up the tabstops
        ReDim TabStop(0 To 2) As Long
      
       'assign values to the tabs for the second, third and fourth
       'column (the initial text is flush against the text box edge)
        TabStop(0) = 90
        TabStop(1) = 130
        TabStop(2) = 185
      
       'set the tabs
        x = SendMessage(Text1.hwnd, EM_SETTABSTOPS, 3, TabStop(0))
         y = SendMessage(Txtedit.hwnd, EM_SETTABSTOPS, 3, TabStop(0))
        Text1.Refresh
        Txtedit.Refresh
        Print x, yEnd Sub
    Private Sub Form_Load()
    With Txtedit
        .Font.Size = "12"
        .SelText = "1" & vbTab & "4" & vbTab & "5" & vbTab & "6" & vbTab & "7" & vbTab & "8" & vbTab & "9" & vbCrLf
        .SelText = "123456789ABCDEFGHI" & vbCrLf & vbCrLf
        .SelText = vbCrLf & vbCrLf & "Notice that the default number of spaces between tabs is approximately 10, based on the RTB's default settings and the size of this font"
        .SelText = vbCrLf & vbCrLf & "This job requires dynamically setting the number of spaces between each tab, anywhere on this page, at any time, no matter how big or small the size of the form is set" & vbCrLf
    End WithWith Text1
        .Font.Size = "12"
        .SelText = "1" & vbTab & "4" & vbTab & "5" & vbTab & "6" & vbTab & "7" & vbTab & "8" & vbTab & "9" & vbCrLf
        .SelText = "123456789ABCDEFGHI" & vbCrLf & vbCrLf
        .SelText = vbCrLf & vbCrLf & "Notice that the default number of spaces between tabs is approximately 10, based on the RTB's default settings and the size of this font"
        .SelText = vbCrLf & vbCrLf & "This job requires dynamically setting the number of spaces between each tab, anywhere on this page, at any time, no matter how big or small the size of the form is set" & vbCrLf
    End With
    End Sub看见x,y结果都是1,但只对textbox有效。
    我想,这会不会跟系统有关???我用的是xp或许在98下有效????
    看看高手们有什么好提议。
      

  10.   

    建议大家用Spy++看看RichTextBox的类名
      

  11.   

    我测试出来,我用的是windows 2000,我把text设置为允许多行,x,y都为1,而且我也曾经试成功过使每个tab都有相同的spaces数,但在换行的时候,就会有问题!
      

  12.   

    建议大家用Spy++看看RichTextBox的类名
    ==========================================
    工具:myspy结果:
    类名:RichTextWndClass
    父句柄:form1.hwnd(容器句柄)
    get child:无child
      

  13.   

    再用Spy看看写字板的类名……RICHEDIT.H里面的RichEdit类是这样写的
    /* Richedit2.0 Window Class. */...
    #define RICHEDIT_CLASSA "RichEdit20A"
    ...
    #define RICHEDIT_CLASSW L"RichEdit20W"
    ...所以,偶怀疑是否真的做过手脚诶~~
      

  14.   

    发现了……
    Unsupported Edit Control Functionality
    Rich edit controls support most but not all functionality for multiline edit controls. This section lists the edit control messages and window styles that are not supported by rich edit controls.The following messages are processed by edit controls but not by rich edit controls.Unsupported message Comments 
    EM_FMTLINES Not supported. 
    EM_GETHANDLE Rich edit controls do not store text as a simple array of characters. 
    EM_GETIMESTATUS Not supported. 
    EM_GETMARGINS Not supported. 
    EM_SETHANDLE Rich edit controls do not store text as a simple array of characters. 
    EM_SETIMESTATUS Not supported. 
    EM_SETMARGINS Supported in Rich Edit 3.0. 
    EM_SETRECTNP Not supported. 
    EM_SETTABSTOPS The EM_SETPARAFORMAT message is used instead. Supported in Rich Edit 3.0. 
    WM_CTLCOLOR The EM_SETBKGNDCOLOR message is used instead. 
    WM_GETFONT The EM_GETCHARFORMAT message is used instead. 
    The following window styles are used with multiline edit controls but not with rich edit controls: ES_LOWERCASE, ES_UPPERCASE, and ES_OEMCONVERT.
      

  15.   

    看看这个:vbAccelerator - Contents of code file: VBRichEdit.ctl:http://www.vbaccelerator.com/home/VB/Utilities/ActiveX_Documenter/ActiveX_Documenter_Source_zip_VBRichEdit_ctl.asp