PC Review


Reply
Thread Tools Rate Thread

change a property does not update custom control

 
 
--== Alain ==--
Guest
Posts: n/a
 
      16th Feb 2007
Hi,

I have some issue with my custom control.
When i change my property "GridLine.Color" my custom control should
redraw its border with the specified color. However, nothing happens.

therefore based on an example from a book i implemented an eventhandler
and tried to manage it like that... but still nothing.

Here is my code example :

public class CGridLine
{
public event EventHandler PropertyChanged;
private Color m_GridLinesColor;

public Color Color
{
get
{
return this.m_GridLinesColor;
}
set
{
this.m_GridLinesColor = value;
this.OnPropertyChanged(EventArgs.Empty);
}
}
....
private void OnPropertyChanged(EventArgs e)
{
if (PropertyChanged != null)
{
PropertyChanged(this, e);
}
}
}

here is my custom control code :
....
public CGridLine GridLines
{
get
{
return this.m_GridLines;
}
set
{
this.m_GridLines = value;
if (GridLinePropertyChanged != null)
{
this.m_GridLines.PropertyChanged -= this.GridLinePropertyChanged;
}
this.GridLinePropertyChanged = new
EventHandler(GridLines.PropertyChanged);
this.m_GridLines.PropertyChanged += this.GridLinePropertyChanged;
this.Invalidate();
}
}
....


Could someone give me an example how to update during design time, the
custom control using eventhandler ?

thanks a lot,

Al.
 
Reply With Quote
 
 
 
 
Marc Gravell
Guest
Posts: n/a
 
      16th Feb 2007
First: for default binding notification events to work, the name is
important: yours should be ColorChanged, not PropertyChanged. This is
a good approach to stick to, as it is a: expected, and b: necessary
for PropertyDescriptor.{Add|Remove}ValueChanged to work correctly
using the default reflection model.

However! There is nothing in the sample provided that would cause it
to redraw when the Color changes; you need to cause invalidate etc -
unless that is hidden in GridLinePropertyChanged (which you haven't
shown us).

Marc


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Property change does not refresh custom control R.A.F. Microsoft C# .NET 3 15th Oct 2007 09:02 AM
How do you access a control property of a main form from a custom user control? forest demon Microsoft C# .NET 6 22nd Aug 2007 11:36 PM
feeding a SQLDataSource embedded in an .ascx user control a custom property assigned to that control Microsoft ASP .NET 4 16th Jul 2006 01:20 PM
can a custom control have an image property that can be set in design time from the property browser? news.austin.rr.com Microsoft Dot NET Compact Framework 3 3rd Mar 2005 02:08 AM
Custom Control Property HelpText Property =?Utf-8?B?R3JleUFsaWVuMDA3?= Microsoft Dot NET Framework Forms 1 20th Jan 2005 06:17 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:48 AM.