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 8 2318
Hi,
I changed your sendmessage api to pass lparam as
STRUCT_CHARFORMAT byref.
Public Class RichTextEx
Inherits RichTextBox
<StructLayout(LayoutKind.Sequential)> _
Public Structure STRUCT_CHARFORMAT
Public cbSize As Integer
Public dwMask As Int32
Public dwEffects As Int32
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, _
ByRef lParam As STRUCT_CHARFORMAT) 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)
SendMessage(Me.Handle, EM_GETCHARFORMAT, SCF_SELECTION, fmt)
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
Ken
---------------------
"Martin Horn" <ma****@nospam.mhorn.co.uk> wrote in message
news:Oa*************@newsfe2-gui.ntli.net...
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
Thanks very much, that has made it work.
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:OJ**************@TK2MSFTNGP10.phx.gbl... Hi,
I changed your sendmessage api to pass lparam as STRUCT_CHARFORMAT byref.
Hi again,
I've encountered another problem with coding this property, this is how I
have it at the moment:
Public Enum BoldStateEnum As Integer
Mixed = 0
Regular = 1
Bold = 2
End Enum
Public Property SelectionBold() As BoldStateEnum
Get
Dim fmt As STRUCT_CHARFORMAT
fmt = GetCharFormat()
If ((fmt.dwMask And CFM_BOLD) = 0) Then
Return BoldStateEnum.Mixed
End If
If ((fmt.dwEffects And CFE_BOLD) = 0) Then
Return BoldStateEnum.Regular
Else
Return BoldStateEnum.Bold
End If
End Get
Set(ByVal value As BoldStateEnum)
Dim fmt As New STRUCT_CHARFORMAT
fmt = GetCharFormat()
If value = BoldStateEnum.Bold Then
fmt.dwMask = fmt.dwMask Or CFM_BOLD
fmt.dwEffects = (fmt.dwEffects Or CFE_BOLD)
Else
' Debug.Assert("SelectionBold = False - Not Implemeted")
End If
SetCharFormat(fmt)
End Set
End Property
Everything seems to work as it should, however when I try to view the form
designer for the form that contains my extended richtext control I get the
following error:
---------------------
One or more errors encountered while loading the designer.The errors are
listed below. Some errors can be fixed by rebuilding your project, while
others may require code changes. Clicking on each error will take you to the
line of code that caused it.
The name 'PC_Till_V2.RichTextBoxEx+BoldStateEnum' is not a valid type name.
---------------------
If I remove the line Me.rtf1.SelectionBold =
RichTextBoxEx.BoldStateEnum.Regular from the form's designer code it allows
the design view to show again.
So whilst I have a workaround for this I would still like to know what I am
doing wrong, as I can't initialise the property properly.
Any ideas?
Thanks,
Martin Horn.
Hi,
I would make sure I build the control before I open the form
designer. If that doesnt work remove the control from the form and add the
control to the toolbox again. Then add it to the form. Maybe it is still
using the older version of the control.
Ken
-----------------
"Martin Horn" <ma****@nospam.mhorn.co.uk> wrote in message
news:UP***************@newsfe2-win.ntli.net...
Hi again,
I've encountered another problem with coding this property, this is how I
have it at the moment:
Public Enum BoldStateEnum As Integer
Mixed = 0
Regular = 1
Bold = 2
End Enum
Public Property SelectionBold() As BoldStateEnum
Get
Dim fmt As STRUCT_CHARFORMAT
fmt = GetCharFormat()
If ((fmt.dwMask And CFM_BOLD) = 0) Then
Return BoldStateEnum.Mixed
End If
If ((fmt.dwEffects And CFE_BOLD) = 0) Then
Return BoldStateEnum.Regular
Else
Return BoldStateEnum.Bold
End If
End Get
Set(ByVal value As BoldStateEnum)
Dim fmt As New STRUCT_CHARFORMAT
fmt = GetCharFormat()
If value = BoldStateEnum.Bold Then
fmt.dwMask = fmt.dwMask Or CFM_BOLD
fmt.dwEffects = (fmt.dwEffects Or CFE_BOLD)
Else
' Debug.Assert("SelectionBold = False - Not Implemeted")
End If
SetCharFormat(fmt)
End Set
End Property
Everything seems to work as it should, however when I try to view the form
designer for the form that contains my extended richtext control I get the
following error:
---------------------
One or more errors encountered while loading the designer.The errors are
listed below. Some errors can be fixed by rebuilding your project, while
others may require code changes. Clicking on each error will take you to the
line of code that caused it.
The name 'PC_Till_V2.RichTextBoxEx+BoldStateEnum' is not a valid type name.
---------------------
If I remove the line Me.rtf1.SelectionBold =
RichTextBoxEx.BoldStateEnum.Regular from the form's designer code it allows
the design view to show again.
So whilst I have a workaround for this I would still like to know what I am
doing wrong, as I can't initialise the property properly.
Any ideas?
Thanks,
Martin Horn.
Hi Ken,
that still didn't fix it. The problem seems to occur if I create an
inherited control class that has a property that reurns an enum value. See
below for an example that demonstrates the problem.
I created a new project with a single form. Then I added the follwing class:
Public Class TestClass
Inherits Button
Private fValue As TestClassEnum
Public Enum TestClassEnum
Value1 = 0
Value2 = 1
End Enum
Public Property ReturnEnum() As TestClassEnum
Get
Return fValue.Value1
End Get
Set(ByVal value As TestClassEnum)
fValue = value
End Set
End Property
End Class
If I close the form designer, save the project then try to re-open the form
designer I get the following error, but I can't see what I'm doing wrong.
-------------------------------------------
One or more errors encountered while loading the designer.The errors are
listed below. Some errors can be fixed by rebuilding your project, while
others may require code changes. Clicking on each error will take you to the
line of code that caused it.
The variable 'Value1' is either undeclared or was never assigned.
Hide
Edit
at
System.ComponentModel.Design.Serialization.CodeDom SerializerBase.Error(IDesignerSerializationManager
manager, String exceptionText, String helpLink)
at
System.ComponentModel.Design.Serialization.CodeDom SerializerBase.DeserializeExpression(IDesignerSeri alizationManager
manager, String name, CodeExpression expression)
at
System.ComponentModel.Design.Serialization.CodeDom SerializerBase.DeserializeAssignStatement(IDesigne rSerializationManager
manager, CodeAssignStatement statement)
at
System.ComponentModel.Design.Serialization.CodeDom SerializerBase.DeserializeStatement(IDesignerSeria lizationManager
manager, CodeStatement statement)
---------------------------------------------------
Thanks,
Martin.
Hi,
Sorry I cant reproduce the error. Make sure you have the latest
service pack for the dotnet framework installed. If you are still having
problems reinstall the dot net framework and as a last resort vb.net http://msdn.microsoft.com/netframewo...s/default.aspx
Ken
------
"Martin Horn" <ma****@nospam.mhorn.co.uk> wrote in message
news:MY**************@newsfe3-win.ntli.net...
Hi Ken,
that still didn't fix it. The problem seems to occur if I create an
inherited control class that has a property that reurns an enum value. See
below for an example that demonstrates the problem.
I created a new project with a single form. Then I added the follwing class:
Public Class TestClass
Inherits Button
Private fValue As TestClassEnum
Public Enum TestClassEnum
Value1 = 0
Value2 = 1
End Enum
Public Property ReturnEnum() As TestClassEnum
Get
Return fValue.Value1
End Get
Set(ByVal value As TestClassEnum)
fValue = value
End Set
End Property
End Class
If I close the form designer, save the project then try to re-open the form
designer I get the following error, but I can't see what I'm doing wrong.
-------------------------------------------
One or more errors encountered while loading the designer.The errors are
listed below. Some errors can be fixed by rebuilding your project, while
others may require code changes. Clicking on each error will take you to the
line of code that caused it.
The variable 'Value1' is either undeclared or was never assigned.
Hide
Edit
at
System.ComponentModel.Design.Serialization.CodeDom SerializerBase.Error(IDesignerSerializationManager
manager, String exceptionText, String helpLink)
at
System.ComponentModel.Design.Serialization.CodeDom SerializerBase.DeserializeExpression(IDesignerSeri alizationManager
manager, String name, CodeExpression expression)
at
System.ComponentModel.Design.Serialization.CodeDom SerializerBase.DeserializeAssignStatement(IDesigne rSerializationManager
manager, CodeAssignStatement statement)
at
System.ComponentModel.Design.Serialization.CodeDom SerializerBase.DeserializeStatement(IDesignerSeria lizationManager
manager, CodeStatement statement)
---------------------------------------------------
Thanks,
Martin.
Okay, so it looks like it's a problem peculiar to my setup, I'll do as you
suggest.
Thanks,
Martin.
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:OW*************@TK2MSFTNGP12.phx.gbl... Hi,
Sorry I cant reproduce the error. Make sure you have the latest service pack for the dotnet framework installed. If you are still having problems reinstall the dot net framework and as a last resort vb.net
http://msdn.microsoft.com/netframewo...s/default.aspx
Ken ------ "Martin Horn" <ma****@nospam.mhorn.co.uk> wrote in message news:MY**************@newsfe3-win.ntli.net... Hi Ken,
that still didn't fix it. The problem seems to occur if I create an inherited control class that has a property that reurns an enum value. See below for an example that demonstrates the problem.
I created a new project with a single form. Then I added the follwing class:
Public Class TestClass Inherits Button Private fValue As TestClassEnum
Public Enum TestClassEnum Value1 = 0 Value2 = 1 End Enum
Public Property ReturnEnum() As TestClassEnum Get Return fValue.Value1 End Get Set(ByVal value As TestClassEnum) fValue = value End Set End Property End Class
If I close the form designer, save the project then try to re-open the form designer I get the following error, but I can't see what I'm doing wrong.
------------------------------------------- One or more errors encountered while loading the designer.The errors are listed below. Some errors can be fixed by rebuilding your project, while others may require code changes. Clicking on each error will take you to the line of code that caused it.
The variable 'Value1' is either undeclared or was never assigned. Hide Edit
at System.ComponentModel.Design.Serialization.CodeDom SerializerBase.Error(IDesignerSerializationManager manager, String exceptionText, String helpLink) at System.ComponentModel.Design.Serialization.CodeDom SerializerBase.DeserializeExpression(IDesignerSeri alizationManager manager, String name, CodeExpression expression) at System.ComponentModel.Design.Serialization.CodeDom SerializerBase.DeserializeAssignStatement(IDesigne rSerializationManager manager, CodeAssignStatement statement) at System.ComponentModel.Design.Serialization.CodeDom SerializerBase.DeserializeStatement(IDesignerSeria lizationManager manager, CodeStatement statement) ---------------------------------------------------
Thanks,
Martin.
Just in case this may help anyone else, I have discovered that moving the
enum outside of the class fixes the problem, as follows:
Public Enum TestClassEnum
Value1 = 0
Value2 = 1
End Enum
Public Class TestClass
Inherits Button
Private fValue As TestClassEnum = TestClassEnum.Value1
Public Property ReturnEnum() As TestClassEnum
Get
Return fValue.Value1
End Get
Set(ByVal value As TestClassEnum)
fValue = value
End Set
End Property
End Class
I hope posting a late update to this topic isn't a problem.
Regards,
Martin Horn.
"Martin Horn" <ma****@nospam.mhorn.co.uk> wrote in message
news:GS***************@newsfe3-win.ntli.net... Okay, so it looks like it's a problem peculiar to my setup, I'll do as you suggest.
Thanks,
Martin.
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message news:OW*************@TK2MSFTNGP12.phx.gbl... Hi,
Sorry I cant reproduce the error. Make sure you have the latest service pack for the dotnet framework installed. If you are still having problems reinstall the dot net framework and as a last resort vb.net
http://msdn.microsoft.com/netframewo...s/default.aspx
Ken ------ "Martin Horn" <ma****@nospam.mhorn.co.uk> wrote in message news:MY**************@newsfe3-win.ntli.net... Hi Ken,
that still didn't fix it. The problem seems to occur if I create an inherited control class that has a property that reurns an enum value. See below for an example that demonstrates the problem.
I created a new project with a single form. Then I added the follwing class:
Public Class TestClass Inherits Button Private fValue As TestClassEnum
Public Enum TestClassEnum Value1 = 0 Value2 = 1 End Enum
Public Property ReturnEnum() As TestClassEnum Get Return fValue.Value1 End Get Set(ByVal value As TestClassEnum) fValue = value End Set End Property End Class
If I close the form designer, save the project then try to re-open the form designer I get the following error, but I can't see what I'm doing wrong.
------------------------------------------- One or more errors encountered while loading the designer.The errors are listed below. Some errors can be fixed by rebuilding your project, while others may require code changes. Clicking on each error will take you to the line of code that caused it.
The variable 'Value1' is either undeclared or was never assigned. Hide Edit
at System.ComponentModel.Design.Serialization.CodeDom SerializerBase.Error(IDesignerSerializationManager manager, String exceptionText, String helpLink) at System.ComponentModel.Design.Serialization.CodeDom SerializerBase.DeserializeExpression(IDesignerSeri alizationManager manager, String name, CodeExpression expression) at System.ComponentModel.Design.Serialization.CodeDom SerializerBase.DeserializeAssignStatement(IDesigne rSerializationManager manager, CodeAssignStatement statement) at System.ComponentModel.Design.Serialization.CodeDom SerializerBase.DeserializeStatement(IDesignerSeria lizationManager manager, CodeStatement statement) ---------------------------------------------------
Thanks,
Martin.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: nouno |
last post by:
I am trying to spell check a richtextbox. Through code (shown below) I
save the contents of the richtextbox to a rtf file, open the rtf file
in Word, spell check it, save it, and then load the ftf...
|
by: blah |
last post by:
if i change my rtb to readonly then when a user presses a keyboad key it
'bings'. how do i stop the noise evertime a user presses a key?
thanks,
Rob
|
by: user |
last post by:
Hello
When i add new lines of text to my RichTextBox, and when vertical scroll
bar appear (there is more text than RichTextBox can display),
RichTextBox always display "the oldest text" (vertical...
|
by: JonnyT |
last post by:
I searched high and low for an answer on how to auto scroll a
richtextbox and now I finally have it. Since it took me a while to
get a good efficient way of doing it that didn't require focus to...
|
by: bjhartin |
last post by:
Hello all,
I am having a problem with extending complex types. I have a simple
base schema (FooBar.xsd) which defines XML documents of the following
form:
<Foo FooAttribute1="aaa">
<Bar...
|
by: James Wong |
last post by:
Hi,
I use the RichTextBox in my program.
It will use different language in this RichTextBox (chinese and english
characters), and it set the "DualFont" and use different fonts.
By the way, how...
|
by: Vivien Parlat |
last post by:
Hello,
I searched hard but couldn't find an answer to that question : what's
wrong in my code (see below), I'm trying to create an extended
RichTextBox, adding new "things" to be painted into...
|
by: interec |
last post by:
I have some code in Java that I need to translate into C++. My Java
code defines a class hierarchy as follows:
// interface IA
public interface IA
{
public abstract void doA();
}
//...
|
by: Vimalathithan |
last post by:
I just developing a editor. I have provide the options like Bold, Italic, underlin, font change, font size change. These font options are keep in with one toolstripbutton. the toolstripbar keep...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |