Hello group,
I design a class to bind it to a property grid for easy modification
of some settings. My problem is now that I want to raise an event when
a settings has been changed.
Thats not a problem with some "normal" properties (see property
DisplayGrid). But when I use a subclass and TypeConverter the setter
of the property is not called.
Set(ByVal value As LineSetting)
m_Limit1 = value
RaiseEvent Limit1Changed(M e, m_Limit1)
End Set
And therefore no event fired.
I already added the attribute
NotifyParentPro pertyAttribute( True)
to the subclass but no change.
Here is my code:
Imports System.Componen tModel
Imports System.Drawing
Public Class Setting
#Region "Private members"
Private m_DisplayGrid As Boolean = True
Private m_Limit1 As New LineSetting(Fal se, Color.AntiqueWh ite)
#End Region
#Region "Events"
Public Event DisplayGridChan ged(ByVal sender As Object, ByVal e As
Boolean)
Public Event Limit1Changed(B yVal sender As Object, ByVal e As
LineSetting)
#End Region
''' <summary>
''' Display grid on Chart
''' </summary>
<CategoryAttrib ute("General"), _
DefaultValueAtt ribute(True), _
DescriptionAttr ibute("Show a grid.")_
Public Property DisplayGrid() As Boolean
Get
Return m_DisplayGrid
End Get
Set(ByVal value As Boolean)
m_DisplayGrid = value
RaiseEvent DisplayGridChan ged(Me, m_DisplayGrid)
End Set
End Property
<CategoryAttrib ute("Limits"), _
Editor(GetType( LineEditor),
GetType(System. Drawing.Design. UITypeEditor)), _
DescriptionAttr ibute("Show Limit 1")_
Public Property Limit1() As LineSetting
Get
Return m_Limit1
End Get
Set(ByVal value As LineSetting)
m_Limit1 = value
RaiseEvent Limit1Changed(M e, m_Limit1)
End Set
End Property
End Class
<TypeConverter( GetType(LineCon verter))_
Public Class LineSetting
Private m_Show As Boolean
Private m_Color As Color
''' <summary>
''' Gets or sets a value indicating whether this <see
cref="LineSetti ng" /is show.
''' </summary>
Public Property Show() As Boolean
Get
Return m_Show
End Get
Set(ByVal value As Boolean)
m_Show = value
End Set
End Property
Public Property Color() As Color
Get
Return m_Color
End Get
Set(ByVal value As Color)
m_Color = value
End Set
End Property
''' <summary>
''' Initializes a new instance of the <see cref="LineSetti ng" />
class.
''' </summary>
Public Sub New()
' set default values
m_Show = False
m_Color = Drawing.Color.A liceBlue
End Sub
''' <summary>
''' Initializes a new instance of the <see cref="LineSetti ng" />
class.
''' </summary>
''' <param name="show">if set to <c>true</c[show].</param>
''' <param name="color">Th e color.</param>
Public Sub New(ByVal show As Boolean, ByVal color As Color)
' set values
m_Show = show
m_Color = color
End Sub
End Class
Friend Class LineConverter
Inherits ExpandableObjec tConverter
Public Overrides Function CanConvertTo(By Val context As
System.Componen tModel.ITypeDes criptorContext, ByVal destinationType As
System.Type) As Boolean
If (destinationTyp e Is GetType(LineSet ting)) Then
Return True
Else
Return MyBase.CanConve rtTo(context, destinationType )
End If
End Function
Public Overrides Function ConvertTo(ByVal context As
System.Componen tModel.ITypeDes criptorContext, ByVal culture As
System.Globaliz ation.CultureIn fo, ByVal value As Object, ByVal
destinationType As System.Type) As Object
If TypeOf value Is LineSetting Then
Dim myLimitSetting As LineSetting = CType(value,
LineSetting)
Return myLimitSetting. Show '
'& "," & myLimitSetting. Color.ToString
Else
Return MyBase.ConvertT o(context, culture, value,
destinationType )
End If
End Function
End Class
Friend Class LineEditor
Inherits System.Drawing. Design.UITypeEd itor
Public Overrides Sub PaintValue(ByVa l e As
System.Drawing. Design.PaintVal ueEventArgs)
Dim myChartLine As LineSetting
Dim fillRegion As New Region(e.Bounds )
' get setting to draw
myChartLine = CType(e.Value, LineSetting)
If myChartLine.Sho w = True Then
Dim myBrush As SolidBrush
myBrush = New SolidBrush(myCh artLine.Color)
e.Graphics.Fill Region(myBrush, fillRegion)
Else
' draw a red cross to indicate false
e.Graphics.Draw Line(Pens.Red, e.Bounds.Left + 1,
e.Bounds.Bottom - 1, e.Bounds.Right - 1, e.Bounds.Top + 1)
End If
End Sub
Public Overrides Function GetPaintValueSu pported(ByVal context As
System.Componen tModel.ITypeDes criptorContext) As Boolean
Return True
End Function
End Class
-------------------------
And this is the code within the form
Public Class Form1
Private OptionsProperty Grid As System.Windows. Forms.PropertyG rid
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim mySettings As New Setting
AddHandler mySettings.Limi t1Changed, AddressOf Limit1Changed
AddHandler mySettings.Disp layGridChanged, AddressOf
DisplayGridChan ged
OptionsProperty Grid = New PropertyGrid()
OptionsProperty Grid.Size = New Size(310, 500)
OptionsProperty Grid.Dock = DockStyle.Fill
Me.Size = New Size(310, 500)
Me.Controls.Add (OptionsPropert yGrid)
Me.Text = "Options Dialog"
OptionsProperty Grid.SelectedOb ject = mySettings
OptionsProperty Grid.PropertySo rt =
PropertySort.Ca tegorizedAlphab etical
End Sub
Public Sub Limit1Changed(B yVal sender As Object, ByVal e As
LineSetting)
Debug.WriteLine ("Limit 1 changed")
End Sub
Public Sub DisplayGridChan ged(ByVal sender As Object, ByVal e As
Boolean)
Debug.WriteLine ("Display Grid changed")
End Sub
End Class
------------------------
Any help ? Thank you
Greetings,
Hans 0 1512 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Koda |
last post by:
What is the difference between class fields and class properties?
Thanks
Mike
|
by: Helen |
last post by:
I have a person class with a name object. The name object has several
fields including one called "title". The two classes look something
like this:
public class name {
public string title {
// get set code here
}
}
|
by: Julia |
last post by:
class Document
{
Hashtable Properties ; //Key is the property name
}
class Media
{
Document document;
|
by: Doug D via .NET 247 |
last post by:
I really really need some insight on this problem
I am trying to bind a strongly typed collection object to a datagrid.
I already Inherited CollectionBase, but .NET says that it cannot find my property name, when I try to bind it to the grid..
now, here is where it gets tricky.
Do I NEED to Implement IBindingList, on my collection object, since my object that I am adding to the collection inherits from a another class?
here is my...
|
by: Joergen Bech |
last post by:
(Slightly religious question):
Suppose I have the following class:
---snip---
Public Class MyClass
Private _MyVariable As Integer
Public Property MyVariable() As Integer
Get
| |
by: kmcmanus |
last post by:
I have just started to write a few business classes that are largely made up
of properties (getters and setters). For each setter I want to fire a
changed event - each event will have a unique name
e.g.
public class CBusinessObject
{
private CProperty<longm_propId;
private CProperty<stringm_propName;
|
by: Henrik Dahl |
last post by:
I have the fragment below as contents of a <Gridelement. The idea is that
if the checkbox is checked the <TreeViewelement should only span one
instead of two columns. When I check the checkbox the background of the
treeview turns red, but the treeview continues to span 2 instead of 1
column. It's a bit like the attached property Grid.ColumnSpan does not get
assigned by the <Setter Property="Grid.ColumnSpan" Value="1"/at all. What
should I...
|
by: Paul Richardson |
last post by:
Hi,
What i'm trying to do is assign a class (i.e. UKPostCode) to a propety of
the UKAddress Class.
So for example:
class UKAddress
{
public string AddressLine1
|
by: GiJeet |
last post by:
hello, I'm trying to use a dictionary as a class member. I want to
use a property to get/set the key/value of the dictionary but I'm
confused as how to use a dictionary as a property. Since there are 2
parts, I don't know how to setup the get/sets. I tried searching but
could not find any examples. I'd appreciate an example of how to get/
set the two parts of a dictionary via a property of a class.
tia
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |