CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2009
    Posts
    1,355

    VB2010- RichTextBox and SendMessage(): how add underline style?

    heres the consts and structure:
    Code:
    #Region "Interop-Defines"
        <StructLayout(LayoutKind.Sequential)> _
        Private Structure CHARFORMAT
            Public cbSize As Integer
            Public dwMask As UInteger
            Public dwEffects As UInteger
            Public yHeight As Integer
            Public yOffset As Integer
            Public crTextColor As Integer
            Public bCharSet As Byte
            Public bPitchAndFamily As Byte
            <MarshalAs(UnmanagedType.ByValArray, SizeConst:=32)> _
            Public szFaceName As Char()
    
            ' CHARFORMAT2 from here onwards.
            Public wWeight As Short
            Public sSpacing As Short
            Public crBackColor As Integer
            Public LCID As Integer
            Public dwReserved As UInteger
            Public sStyle As Short
            Public wKerning As Short
            Public bUnderlineType As Byte
            Public bAnimation As Byte
            Public bRevAuthor As Byte
        End Structure
    
        <DllImport("user32", CharSet:=CharSet.Auto)> _
        Private Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As Integer, ByRef lp As CHARFORMAT) As Integer
        End Function
    
        Private Const WM_USER As Integer = &H400
        Private Const EM_GETCHARFORMAT As Integer = WM_USER + 58
        Private Const EM_SETCHARFORMAT As Integer = WM_USER + 68
        Private Const SCF_SELECTION As Integer = &H1
        Private Const SCF_WORD As Integer = &H2
        Private Const SCF_ALL As Integer = &H4
    
    #Region "CHARFORMAT2 Flags"
        Private Const CFE_BOLD As UInt32 = &H1
        Private Const CFE_ITALIC As UInt32 = &H2
        Private Const CFE_UNDERLINE As UInt32 = &H4
        Private Const CFE_STRIKEOUT As UInt32 = &H8
        Private Const CFE_PROTECTED As UInt32 = &H10
        Private Const CFE_LINK As UInt32 = &H20
        Private Const CFE_AUTOCOLOR As UInt32 = &H40000000
        Private Const CFE_SUBSCRIPT As UInt32 = &H10000
        ' Superscript and subscript are 
        Private Const CFE_SUPERSCRIPT As UInt32 = &H20000
        ' mutually exclusive 
        Private Const CFM_SMALLCAPS As Integer = &H40
        ' (*) 
        Private Const CFM_ALLCAPS As Integer = &H80
        ' Displayed by 3.0 
        Private Const CFM_HIDDEN As Integer = &H100
        ' Hidden by 3.0 
        Private Const CFM_OUTLINE As Integer = &H200
        ' (*) 
        Private Const CFM_SHADOW As Integer = &H400
        ' (*) 
        Private Const CFM_EMBOSS As Integer = &H800
        ' (*) 
        Private Const CFM_IMPRINT As Integer = &H1000
        ' (*) 
        Private Const CFM_DISABLED As Integer = &H2000
        Private Const CFM_REVISED As Integer = &H4000
        Private Const CFM_BACKCOLOR As Integer = &H4000000
        Private Const CFM_LCID As Integer = &H2000000
        Private Const CFM_UNDERLINETYPE As Integer = &H800000
        ' Many displayed by 3.0 
        Private Const CFM_WEIGHT As Integer = &H400000
        Private Const CFM_SPACING As Integer = &H200000
        ' Displayed by 3.0 
        Private Const CFM_KERNING As Integer = &H100000
        ' (*) 
        Private Const CFM_STYLE As Integer = &H80000
        ' (*) 
        Private Const CFM_ANIMATION As Integer = &H40000
        ' (*) 
        Private Const CFM_REVAUTHOR As Integer = &H8000
        Private Const CFM_BOLD As UInt32 = &H1
        Private Const CFM_ITALIC As UInt32 = &H2
        Private Const CFM_UNDERLINE As UInt32 = &H4
        Private Const CFM_STRIKEOUT As UInt32 = &H8
        Private Const CFM_PROTECTED As UInt32 = &H10
        Private Const CFM_LINK As UInt32 = &H20
        Private Const CFM_SIZE As UInt32 = &H8000000
        Private Const CFM_COLOR As UInt32 = &H40000000
        Private Const CFM_FACE As UInt32 = &H20000000
        Private Const CFM_OFFSET As UInt32 = &H10000000
        Private Const CFM_CHARSET As UInt32 = &H8000000
        Private Const CFM_SUBSCRIPT As UInt32 = CFE_SUBSCRIPT Or CFE_SUPERSCRIPT
        Private Const CFM_SUPERSCRIPT As UInt32 = CFM_SUBSCRIPT
        Private Const CFU_UNDERLINENONE As Byte = &H0
        Private Const CFU_UNDERLINE As Byte = &H1
        Private Const CFU_UNDERLINEWORD As Byte = &H2
        ' (*) displayed as ordinary underline 
        Private Const CFU_UNDERLINEDOUBLE As Byte = &H3
        ' (*) displayed as ordinary underline 
        Private Const CFU_UNDERLINEDOTTED As Byte = &H4
        Private Const CFU_UNDERLINEDASH As Byte = &H5
        Private Const CFU_UNDERLINEDASHDOT As Byte = &H6
        Private Const CFU_UNDERLINEDASHDOTDOT As Byte = &H7
        Private Const CFU_UNDERLINEWAVE As Byte = &H8
        Private Const CFU_UNDERLINETHICK As Byte = &H9
        Private Const CFU_UNDERLINEHAIRLINE As Byte = &HA
        ' (*) displayed as ordinary underline 
    #End Region
    #End Region
    heres how i use it:
    Code:
     Public Sub SelectionUnderline(ByVal UTUnderlineType As UnderlineStyle, Optional ByVal UnderlineColor As UnderlineColor = PlusRichTextBox.UnderlineColor.Black)
            Dim fmt As CHARFORMAT = New CHARFORMAT()
            fmt.cbSize = Marshal.SizeOf(fmt)
            fmt.dwMask = CFM_UNDERLINETYPE Or CFM_UNDERLINE
                fmt.bUnderlineType = CByte(CByte(UTUnderlineType) / CByte(UnderlineColor))
    
            If SendMessage(Me.Handle, EM_SETCHARFORMAT, SCF_SELECTION, fmt) <> EM_SETCHARFORMAT Then Debug.Print(Marshal.GetLastWin32Error().ToString)
        End Sub
    on error, i get zero.
    so how can i change the uderline type and color?
    (the underline isn't showed and i don't know why)

  2. #2
    Join Date
    Apr 2009
    Posts
    1,355

    Re: VB2010- RichTextBox and SendMessage(): how add underline style?

    how can i combine correctly the color with type?
    (if i don't use the color, the underline is showed)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured