M
Martin Horn
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(LayoutKind.Sequential)> _
Public Structure STRUCT_CHARFORMAT
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(UnmanagedType.ByValArray, SizeConst:=32)> _
Public szFaceName As Char()
End Structure
<DllImport("user32.dll")> _
Private Shared Function SendMessage(ByVal hWnd As IntPtr, _
ByVal msg As Int32, _
ByVal wParam As Int32, _
ByVal lParam As IntPtr) As Int32
End Function
Public Const EM_GETCHARFORMAT 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_CHARFORMAT
fmt.cbSize = Marshal.SizeOf(fmt)
Dim lParam As IntPtr
lParam = Marshal.AllocCoTaskMem(Marshal.SizeOf(fmt))
Marshal.StructureToPtr(fmt, lParam, False)
SendMessage(Me.Handle, EM_GETCHARFORMAT, 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(LayoutKind.Sequential)> _
Public Structure STRUCT_CHARFORMAT
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(UnmanagedType.ByValArray, SizeConst:=32)> _
Public szFaceName As Char()
End Structure
<DllImport("user32.dll")> _
Private Shared Function SendMessage(ByVal hWnd As IntPtr, _
ByVal msg As Int32, _
ByVal wParam As Int32, _
ByVal lParam As IntPtr) As Int32
End Function
Public Const EM_GETCHARFORMAT 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_CHARFORMAT
fmt.cbSize = Marshal.SizeOf(fmt)
Dim lParam As IntPtr
lParam = Marshal.AllocCoTaskMem(Marshal.SizeOf(fmt))
Marshal.StructureToPtr(fmt, lParam, False)
SendMessage(Me.Handle, EM_GETCHARFORMAT, 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