Hi,
I am trying to add extra functionality to the standard RichText control, but
I've fallen at the first hurdle,can someone take a look at the following
code and tell me why it fails to return true if the current selection is
bold.
Thanks,
Martin Horn.
Imports System.Runtime. InteropServices
Public Class RichTextEx
Inherits RichTextBox
<StructLayout(L ayoutKind.Seque ntial)> _
Public Structure STRUCT_CHARFORM AT
Public cbSize As Integer
Public dwMask As UInt32
Public dwEffects As UInt32
Public yHeight As Int32
Public yOffset As Int32
Public crTextColor As Int32
Public bCharSet As Byte
Public bPitchAndFamily As Byte
<MarshalAs(Unma nagedType.ByVal Array, SizeConst:=32)> _
Public szFaceName As Char()
End Structure
<DllImport("use r32.dll")> _
Private Shared Function SendMessage(ByV al hWnd As IntPtr, _
ByVal msg As Int32, _
ByVal wParam As Int32, _
ByVal lParam As IntPtr) As Int32
End Function
Public Const EM_GETCHARFORMA T As Int32 = &H43A&
Public Const SCF_SELECTION As Int32 = &H1&
Public Const CFM_BOLD As Int32 = &H1&
Public Const CFE_BOLD As Int32 = &H1&
' Just to test the SelectionBold Property
Public Sub New()
MyBase.New()
Me.Font = New Font("Times New Roman", 10, FontStyle.Bold)
End Sub
Public Property SelectionBold() As Boolean
Get
Dim fmt As New STRUCT_CHARFORM AT
fmt.cbSize = Marshal.SizeOf( fmt)
Dim lParam As IntPtr
lParam = Marshal.AllocCo TaskMem(Marshal .SizeOf(fmt))
Marshal.Structu reToPtr(fmt, lParam, False)
SendMessage(Me. Handle, EM_GETCHARFORMA T, SCF_SELECTION, lParam)
If ((fmt.dwMask And CFM_BOLD) = 0) Then
Return False
End If
If ((fmt.dwEffects And CFE_BOLD) = 0) Then
Return False
Else
Return True
End If
End Get
Set(ByVal value As Boolean)
'// Not Implemented //
End Set
End Property
End Class
I am trying to add extra functionality to the standard RichText control, but
I've fallen at the first hurdle,can someone take a look at the following
code and tell me why it fails to return true if the current selection is
bold.
Thanks,
Martin Horn.
Imports System.Runtime. InteropServices
Public Class RichTextEx
Inherits RichTextBox
<StructLayout(L ayoutKind.Seque ntial)> _
Public Structure STRUCT_CHARFORM AT
Public cbSize As Integer
Public dwMask As UInt32
Public dwEffects As UInt32
Public yHeight As Int32
Public yOffset As Int32
Public crTextColor As Int32
Public bCharSet As Byte
Public bPitchAndFamily As Byte
<MarshalAs(Unma nagedType.ByVal Array, SizeConst:=32)> _
Public szFaceName As Char()
End Structure
<DllImport("use r32.dll")> _
Private Shared Function SendMessage(ByV al hWnd As IntPtr, _
ByVal msg As Int32, _
ByVal wParam As Int32, _
ByVal lParam As IntPtr) As Int32
End Function
Public Const EM_GETCHARFORMA T As Int32 = &H43A&
Public Const SCF_SELECTION As Int32 = &H1&
Public Const CFM_BOLD As Int32 = &H1&
Public Const CFE_BOLD As Int32 = &H1&
' Just to test the SelectionBold Property
Public Sub New()
MyBase.New()
Me.Font = New Font("Times New Roman", 10, FontStyle.Bold)
End Sub
Public Property SelectionBold() As Boolean
Get
Dim fmt As New STRUCT_CHARFORM AT
fmt.cbSize = Marshal.SizeOf( fmt)
Dim lParam As IntPtr
lParam = Marshal.AllocCo TaskMem(Marshal .SizeOf(fmt))
Marshal.Structu reToPtr(fmt, lParam, False)
SendMessage(Me. Handle, EM_GETCHARFORMA T, SCF_SELECTION, lParam)
If ((fmt.dwMask And CFM_BOLD) = 0) Then
Return False
End If
If ((fmt.dwEffects And CFE_BOLD) = 0) Then
Return False
Else
Return True
End If
End Get
Set(ByVal value As Boolean)
'// Not Implemented //
End Set
End Property
End Class
Comment