Win control refreshing at designtime

G

Guest

Hi all

Im currently constructing a Windows control that inherits from RichTextBox,
but I'm having a bit of trouble with updating the control at design time.

The senario is SIMPLIFIED as follows:

My RichTextBox control :

Public Class Crtb
Inherits RichTextBox

private _indentifiers() as Identifier ' An array of Indentifier objects

Public Sub RefreshRtb
' Refreshes the Box acording to the Identifiers
End Sub

Public Overloads Sub AddIndentifier(ByVal characters As String, ByVal
color As System.Drawing.Color)
ReDim Preserve Me._indentifiers(Me._indentifiers.GetUpperBound(0) + 1)
Me._indentifiers(Me._indentifiers.GetUpperBound(0)) = New
Identifier(characters, color)
End Sub

End Class


An Identifier Class holding a KeyWord as _formatCharacters and a Color to
use in the RTB for this keyword:

< Serializable()> _
Public Class Identifier
Private _formatCharacters As String
Private _color As System.Drawing.Color

Public Property FormatCharacters() As String
......
Public Property Color() As System.Drawing.Color
.....
Public Sub New()
Me._formatCharacters = ""
Me._color = System.Drawing.Color.Blue
End Sub

Public Sub New(formatCharacters As String, color as System.Drawing.Color)
me._formatCharacters = formatCharacters
me._color = color
End Sub

End Class


This is very simplified but should give a picture of the senario.

Now when adding a control to a form I can edit the Identifiers property
array at design time, and so add new Identifiers and e.g. change the color of
the existing ones.

My problem is that I want the RTB control to refresh itself on designtime
when I change e.g. a color property of one of the Identifiers objects in the
array. This can be done by adding an event to the Identifier class and
thereafter adding a handle that calls Refresh for this event each time a new
Identifier is added to The RTB.

This though gives me a big problem since an eventhandler is not able to be
serialized, which meens that the refresh functionallity disappears when I run
the app and return to design mode. As far as I know the control saves it's
state in the resx file, but since the event handlers can't be serialized this
part of the control is lost.

This is a senario that is used in many controls out there, so I hope that
someone is able to tell me how to get this designtime refresh functionallity
in some other way.

Thanks in advance

Allan
 
A

Ahmed

Your color property should look like:

Public Property Color() As System.Drawing.Color
get

set (byval value as color)
_color = value
me.invalidate <---- add this line if you did not do so.
end property

Ahmed
 
F

Farouche

Ahmed said:
Your color property should look like:

Public Property Color() As System.Drawing.Color
get

set (byval value as color)
_color = value
me.invalidate <---- add this line if you did not do so.
end property

Ahmed

Thanks Ahmed, but that just won't do the trick since my color property is
not on the Control itself, but on an "Identifier" object contained in an
Array on the control


Allan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top